You can pipe the coredump directly into a program that saves the trace to a temporary location, fetches the backtrace, then puts it somewhere the user can access it, then removes the core.
See man 5 core
for an example of how to do something with a coredump pattern.
Essentially you can set the kernel control value kernel.coredump_pattern
pipe the coredump into a specific program. This way you have total control over the logic of when to save a coredump and when not to. Be aware that the program you pipe into runs as root!
|/usr/local/bin/coredump_it.sh
would be an example of doing this.
Alternatively, systemd
already provides functionality to do this. If you set the coredump pattern like so
kernel.core_pattern = |/usr/lib/systemd/systemd-coredump %p %u %g %s %t %e
Then you can use the command coredumpctl
to store and to retrieve the backtrace of the said coredump. For example where the coredump is for PID 24164..
coredumpctl info 24164
$ coredumpctl info 24164
PID: 24164 (bintree)
UID: 1000 (matthew)
GID: 1000 (matthew)
Signal: 11 (SEGV)
Timestamp: Mon 2015-02-09 19:14:13 GMT (1 months 19 days ago)
Command Line: ./bintree
Executable: /home/matthew/Testbed/trees/binary/bintree
Control Group: /user.slice/user-1000.slice/session-1.scope
Unit: session-1.scope
Slice: user-1000.slice
Session: 1
Owner UID: 1000 (matthew)
Boot ID: 82a18962ecc34109965530967f12150b
Machine ID: 69d27b356a94476da859461d3a3bc6fd
Hostname: home.localdomain
Message: Process 24164 (bintree) of user 1000 dumped core.
Stack trace of thread 24164:
#0 0x0000000000400680 bintree_fetch (bintree)
#1 0x0000000000400a7e main (bintree)
#2 0x000000316fc1ffe0 __libc_start_main (libc.so.6)
#3 0x0000000000400589 _start (bintree)
You can just call coredumpctl
directly to get a list of coredumps saved.