Friday, August 15, 2014

Linux Process Profiling - Creating Core Dump

This is the first post in series of Process Profiling, in this post I will show how to create a core dump of a process. We can use following tools to do the core dump of the process.

1. Using Standard Signal  QUIT (3)
2. Using gdb  - GNU Debugger

 We will use the GNU Debugger here.

 #ulimit -c    /* Checking whether cored dump is disabled or enabled
0                  /* Disabled 
#ulimit -c unlimited    /* Changing the sized to unlimited

$ulimit -a
 core file size          (blocks, -c) unlimited
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 65536
max locked memory       (kbytes, -l) 32
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 65536
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

 # ps aux | egrep 'VSZ| 24291'  /* Identifying the Virtual Memory Size of the Process 24291

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root     24291  0.8  0.0   4656  1032 pts/30   S    09:47   0:06 /bin/bash ./generate_core_test.sh
root     28349 19.0  0.0   4048   736 pts/14   R+   09:59   0:00 egrep VSZ| 24291


#gdb --pid=24291 /*Using the specific Process Number to generate its core; The core will be generated in present working directory, ensure that you have enough space.

GNU gdb Red Hat Linux (6.6-45.fc8rh)
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu".
Attaching to process 24291
Reading symbols from /bin/bash...(no debugging symbols found)...done.
Using host libthread_db library "/lib/libthread_db.so.1".
Reading symbols from /lib/libtinfo.so.5...(no debugging symbols found)...done.
Loaded symbols for /lib/libtinfo.so.5
Reading symbols from /lib/libdl.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib/libdl.so.2
Reading symbols from /lib/libc.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib/libc.so.6
Reading symbols from /lib/ld-linux.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib/ld-linux.so.2

(no debugging symbols found)
0x00110416 in __kernel_vsyscall ()

(gdb) gcore  /* Creating the Core
Saved corefile core.24291

(gdb) quit  /* Quiting the gdb
The program is running.  Quit anyway (and detach it)? (y or n) y
Detaching from program: /bin/bash, process 24291

# ls -latrh /* The core file is generated
-rw-r--r--  1 root     root     4.6M 2014-08-15 10:00 core.24291