17

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.

John Dibling
  • 649
  • 2
  • 7
  • 16
  • Wondering if any of the replies was helpful to you? – PythonLearner Jul 29 '12 at 12:54
  • @Valentin: From an educational perspective, yes, the replies were helpful and I upvoted them. However they did not answer the question I actually asked, which was how to construct a dump file which I can then take to a dev machine and examine. I was looking for something analogous to a Windows minidump file. – John Dibling Aug 01 '12 at 21:44

4 Answers4

17

Well the way to create a dump file is:

   gcore - Generate a core file for a running process

SYNOPSIS gcore [-o filename] pid

HackerBaloo
  • 286
  • 2
  • 4
8
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/passwd

If 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>
PythonLearner
  • 846
  • 7
  • 14
5

Try this:

cat /proc/<pid>/smaps > mem.txt

This link might also help you.

inf
  • 2,751
  • 2
  • 18
  • 21
3

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 process

So 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.

0xC0000022L
  • 6,819
  • 10
  • 50
  • 82