Is it possible to get a core dump of a running process and its symbol table?
Question
Is it possible to get gdb or use some other tools to create a core dump of a running process and it's symbol table? It would be great if there's a way to do this without terminating the process.
If this is possible, what commands would you use? (I'm trying to do this on a Linux box)
Solution
$ gdb --pid=26426 (gdb) gcore Saved corefile core.26426 (gdb) detach
OTHER TIPS
Or run gcore $(pidof processname)
.
This has the benefit (over running gdb and issuing commands to the CLI) that you attach and detach in the shortest possible time.
Note: The following method will terminate the running process & requires the symbols too.
You can send one of the following signals (with action=core) to the running process:
From: http://man7.org/linux/man-pages/man7/signal.7.html
Signal Value Action Comment
──────────────────────────────────────────────────────────────────────
SIGHUP 1 Term Hangup detected on controlling terminal
or death of controlling process
SIGINT 2 Term Interrupt from keyboard
SIGQUIT 3 Core Quit from keyboard
SIGILL 4 Core Illegal Instruction
SIGABRT 6 Core Abort signal from abort(3)
SIGFPE 8 Core Floating point exception
SIGKILL 9 Term Kill signal
SIGSEGV 11 Core Invalid memory reference
SIGPIPE 13 Term Broken pipe: write to pipe with no
readers
SIGALRM 14 Term Timer signal from alarm(2)
SIGTERM 15 Term Termination signal
SIGUSR1 30,10,16 Term User-defined signal 1
SIGUSR2 31,12,17 Term User-defined signal 2
SIGCHLD 20,17,18 Ign Child stopped or terminated
SIGCONT 19,18,25 Cont Continue if stopped
SIGSTOP 17,19,23 Stop Stop process
SIGTSTP 18,20,24 Stop Stop typed at terminal
SIGTTIN 21,21,26 Stop Terminal input for background process
SIGTTOU 22,22,27 Stop Terminal output for background process
Like so:
kill <signal> <pid>
And once you have the core, you can open in gdb along with the symbol file.
You can used generate-core-file
command in gdb to generate core dump of running process.