Nektarios
Nektarios

Reputation: 10371

Force a core to dump from an active, normally running program on FreeBSD

I'm writing error handling code for a server on FreeBSD. For extremely serious errors I want to avoid data corruption by immediately terminating. That's easy, exit(3). Before I exit, I output my relevant variables that led me there. However, ideally, this termination would be accompanied by a .core so that I could fully investigate what got me to this catastrophic (and likely hard to reproduce) state.

How can I force this to happen?

Upvotes: 35

Views: 69308

Answers (6)

Pedro Gimeno
Pedro Gimeno

Reputation: 3115

I had no luck with kill -QUIT in a particular case. What worked for me is:

gdb --pid <process_id> -ex "set confirm off" -ex generate-core-file -ex q

Upvotes: 3

Maik Ro
Maik Ro

Reputation: 330

You could also try kill -BUS <pid> which worked for me (though on ubuntu 20.04)

Upvotes: 0

Marvin
Marvin

Reputation: 11

On sles12.. Below code worked for me :

kill -11

The previous suggestions did not do anything.

Upvotes: 1

Edward Tomasz Napierala
Edward Tomasz Napierala

Reputation: 1836

You might also want to take a look at gcore(1) (http://man.freebsd.org/gcore).

Upvotes: 5

Aadishri
Aadishri

Reputation: 1471

This helped me! kill -11 always works for me. 11 is SIGSEGV (invalid memory reference)

Upvotes: 11

msw
msw

Reputation: 43487

kill -QUIT process_id will cause a core dump from a running process (assuming that resource limits allow it).

Or see man 3 abort for causing a program to dump itself.

Added: From an interactive shell, a running program can be made to abort with the quit key, usually Ctrl+\, which sends a SIGQUIT just as the more common Ctrl+C sends a SIGINT. This is identical to the kill -QUIT… it's just easier to type if you are on the controlling terminal. See man 1 stty if your default quit key is different.

Upvotes: 53

Related Questions