How Can I Create A Dump File of a Running Process in Linux?
Mia Lopez
I have a process that is spinning out of control under Linux, and I would like to create a dump file that I can take to my dev machine, and examine there.
In Windows, it is possible to create a "minidump" of a running program in several different ways, including ADVPlus and Windows Task Manager, by going to the Processes tab and right-click selecting "Create Dump File."
Is there a way to accomplish this in Linux?
I would need call stacks, heap and stack memory (especially stack), exceptions and all the rest.
24 Answers
Well the way to create a dump file is:
gcore - Generate a core file for a running processSYNOPSIS gcore [-o filename] pid
pmap <PID>or
strace -f -o xxx -p <PID> might be the tools you are looking for.
pmap shows you an overview about the memory usage of the provided process. strace tracks down every action a process takes. With -f you tell strace to also consider watching over child processes and -o xxx tells strace to write the output to a file. You can also start a new process by using strace, e.g. with
strace cat /etc/passwdIf you are interested in specific information only, such as what files were opened, you can start strace accordingly:
strace -f -o xxx -e trace=open -p <PID> Try this:
cat /proc/<pid>/smaps > mem.txtThis link might also help you.
Meanwhile ProcDump from the Sysinternals suite has also been made available under the very liberal MIT license from the respective GitHub page.
Usage: procdump [OPTIONS...] TARGET OPTIONS -C CPU threshold at which to create a dump of the process from 0 to 100 * nCPU -c CPU threshold below which to create a dump of the process from 0 to 100 * nCPU -M Memory commit threshold in MB at which to create a dump -m Trigger when memory commit drops below specified MB value. -n Number of dumps to write before exiting -s Consecutive seconds before dump is written (default is 10) TARGET must be exactly one of these: -p pid of the processSo as you can deduce from the command line arguments, it's easy to take "snapshots" of a process you know misbehaves by taking up undue amounts of resources to be later analyzed with gdb or so.
This ProcDump for Linux is, however, not feature-complete in comparison with its Windows cousin.