Thursday, December 8, 2011

force a program to dump core

"Core dumped" means that the kernel saved the state of your executing program in a file called core in the current directory.

You can also force a program to dump core by typing ctrl-\ if it is running in the foreground, or by the command kill -3 if it is in the background.

There are two programs for poking around in the corpse, adb and sdb. Like most debuggers, they are arcane, complicated, and indispensable.

The UNIX programming Environment P.188

===

2.4.1.11. This dumping core business sounds as though it could be quite useful, if I can make it happen when I want to. Can I do this, or do I have to wait until there is an error?

Yes, just go to another console or xterm, do

% ps

to find out the process ID of your program, and do

% kill -ABRT pid

where pid is the process ID you looked up.

This is useful if your program has got stuck in an infinite loop, for instance. If your program happens to trap SIGABRT, there are several other signals which have a similar effect.

Alternatively, you can create a core dump from inside your program, by calling the abort() function. See the manual page of abort(3) to learn more.

If you want to create a core dump from outside your program, but do not want the process to terminate, you can use the gcore program. See the manual page of gcore(1) for more information.

http://www.freebsd.org/doc/en/books/developers-handbook/tools-compiling.html

No comments: