0

I want to dump a process' memory when it exits. All the solutions I've seen using gcore, gdb or even procdump for linux dump the core in the middle of the execution and not exactly when it terminates

Procdump for windows has a very elegant solution for this, i.e. -t will allow procdump to create a dump when the process exits.

I stumbled on to ulimit -c unlimited but this again will only generate dumps for non-graceful exits.

The process I want a dump for can be any process and not exactly my application.

Karan Jit Singh
  • 595
  • 7
  • 25
  • 1
    But when the process exits, there is nothing to dump because the process does not exist anymore. What do you mean by "process exits"? – ks1322 Mar 08 '18 at 10:53
  • install signal handler for your application, when its about to exit just dump using C code, following link does that in C https://stackoverflow.com/questions/3342335/dump-memory-of-a-process – Prabhakar Lad Mar 08 '18 at 11:09
  • @ks1322, by when the process exits, what i mean is when it is about to exit. Exactly what windows' procdump `-t` option does. – Karan Jit Singh Mar 08 '18 at 11:16
  • @PrabhakarLad, It's not my process' memory i need dumped. It can be any process, I just need to have a process id and dump the memory right when the process is about to exit. – Karan Jit Singh Mar 08 '18 at 11:18
  • write a c application (install signal handler SIGCHILD), fork a process for which you want to monitor and refer the link in my earlier post to dump the memory. – Prabhakar Lad Mar 08 '18 at 11:25

1 Answers1

1

If you want to mimic this behavior with gdb:

Procdump for windows has a very elegant solution for this, i.e. -t will allow procdump to create a dump when the process exits.

First you create a file 'mycommand.txt':

b exit
r
generate-core-file ./core.1
q

Then you start your program with:

 gdb --command mycommand.txt yourprogram 

you will have a file called core.1 in your working directory. Check with:

gdb yourprogram core.1
Jens Harms
  • 406
  • 3
  • 5