How to generate core file of a process id in Linux ?

Today we will look how to generate core file of any process in linux.

Lets see how to generate core file of current logged in bash shell process.

Generating core file using PID

### Get the current shell process id.
[root@nglinux ~]# echo $$

### Now get the logged in shell process id.
[root@nglinux ~]# ps -ef | grep 17230
root     17230 17225  0 17:53 pts/1    00:00:01 -bash
root     21803 17230 31 22:00 pts/1    00:00:00 ps -ef
root     21804 17230  0 22:00 pts/1    00:00:00 grep 17230

### Generate Core file using the PID
[root@nglinux ~]# gcore 17230
0x00b2a424 in __kernel_vsyscall ()
Saved corefile core.17230
[root@nglinux ~]#

We can see above that core file is now saved as core.17230 and we can debug it to know the process behavior.

Debugging Core File

[root@nglinux ~]# gdb core.17230
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-92.el6)
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-redhat-linux-gnu".
For bug reporting instructions, please see:
Missing separate debuginfo for the main executable file
Try: yum --enablerepo='*-debug*' install /usr/lib/debug/.build-id/b4/87e049ff6120fdb3aace55b1d2420b49939be1
[New Thread 17230]
Core was generated by `-bash'.
#0  0x00b2a424 in __kernel_vsyscall ()
"/root/core.17230" is a core file.
Please specify an executable to debug.

In the above output we can see that core file was generated by -bash process.

And further we can debug it to know how the process was running and why core file is generated.

I hope now you can generate the core file using gcore command.

I am still learning about it more and will post in few days how to debug the core file.

Do post your comments/suggestions below.

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments