2

all

My C++ program generates core dump as large as 2GB and it quickly fills up all usable disc space. What I really need is only backtrace. I was wondering what's the safe size of core dump file if I want to preserve the backtrace. Also, I was wondering if there are other smart solutions.

Thanks! James

James Gan
  • 376
  • 1
  • 5
  • 10
  • 2
    This is a question about managed a limited systems resources. If this is not about "managing information technlogy systems in a business environment" I dont know what is.. – Matthew Ife Mar 31 '15 at 18:22
  • I would suggest just modifying your program to generate a backtrace rather than a core dump in the first place, at least as a compile-time option. – David Schwartz Apr 01 '15 at 00:44

1 Answers1

2

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.

Matthew Ife
  • 22,927
  • 2
  • 54
  • 71