Under Linux, is it possible to gcore a process whose executable has been removed?
While programming on CentOS 6.6, I removed an executable that ran in a screen session (oops,
Now, it doesn’t matter, I want to debug something through
the gcore process. I rebuilt the executable, but
gcore doesn’t accept the replaced file. It knows that the original file has been deleted and won’t let me dump the core.
# gcore 15659 core. YGsoec:4: Error in sourced command file: /home/dev/bin/daemon/destinyd (deleted): No such file or directory. gcore: failed to create core.15659 # ls -l /proc/15659/exe lrwxrwxrwx. 1 root root 0 Mar 12 21:33 /proc/15659/exe -> /home/dev/bin/daemon/destinyd (deleted) # ln -s /proc/15659/exe /home/dev/bin/daemon/destinyd ln: creating symbolic link `/home/dev/bin/daemon/destinyd': File exists # rm /proc/15659/exe rm: remove symbolic link `/proc/15659/exe'? y rm: cannot remove `/proc/15659/exe': Permission denied
gcore has an optional parameter “executable“, It looks promising (as if I could specify a binary that is not /
proc/15659/exe to use), but that didn’t work for me Linux’s
gcore doesn’t have any such arguments.
Is there any workaround? Or do I just need to restart the process (using the recreated executable) and wait for the bug I’m tracking to reproduce?
Despite the output
of ls -l/proc/15659/exe, the original executable is actually available via that path.
So not only was I able to restore the
original file using a simple
cp (although this wasn’t enough to restore the link and get
gcore working), but I was able to attach the GDB to the process using this path as an executable:
# gdb -p 15659 /proc/15659/exe
Then run the “
generate-core-file” command, followed by “
I am then free to check the core file as needed:
# gdb /proc/15659/exe core.15659
In fact, I forgot about GDB’s ability to generate core files, and I was anxious about actually attaching GDB to a process because timing is very important: generating core files at the exact right time to catch that error.
But nos steered me back onto this path and, my fears were clearly superfluous, GDB was able to generate a lovely
core.15659 for me.