24

I'm looking for a way to take a non-intrusive coredump of a running process on Linux.

I'm familiar with gdb's gcore, but that can only be run when gdb is attached to the process and it's stopped for debugging. For a big core dump that might mean many seconds, or even a few minutes, of interrupted execution.

Is there any non-blocking alternative?

Linux supports copy-on-write memory, which it relies upon to support fork() without exec(). So I'm thinking of something kernel-level where the kernel takes a copy-on-write snapshot of the process page tables of the process being dumped, then writes the core out while the original process keeps on running.

I'm pretty sure I could use gdb to force a fork() then dump the child while the parent carries on happily, then wait() in the parent to reap the child after termination. It's messy, though, and still requires two interruptions of the parent process, albeit short ones.

Surely someone's needed this before?

  • I am sorry that I can give only a single upvote for this wonderful question. – peterh - Reinstate Monica Sep 11 '14 at 7:36
  • Excellent question and I, for one, am looking forward to the answer. +1 from me – thanasisk Sep 11 '14 at 7:58
  • 1
    What about 1) attaching the process with gdb 2) let it be forked by a "call fork" command 3) dumping the core of the child process 4) letting the dead child be waited by the parent (another "call wait4") 5) detach from the process 6) automatize 1-5 ? Gdb uses simple sys_ptrace() system calls, it could be a not really complex C tool totally independent from the gdb. – peterh - Reinstate Monica Sep 11 '14 at 8:09
  • 1
    On a virtual machine you could take a snapshot and bring that up as a clone to be analyze. Perhaps one of the tools listed here will help you: cyberciti.biz/programming/linux-memory-forensics-analysis-tools – Giovanni Tirloni Sep 12 '14 at 17:37
  • 1
    You could avoid the second interruption by having the child process also fork and then exit. Then the parent process can wait for the child immediately and then continue, while the grandparent dumps core. – kasperd Sep 28 '14 at 0:24
1

Google CoreDumper springs to mind. It makes a copy-on-write copy of the process's address space, see WriteCoreDump() (see "Notes").

  • That looks exceedingly useful! I wonder what the underlying technique used is. Presumably it ptraces the process, but the creation of the CoW snapshot without forking and in a way that doesn't affect the stack(s) would be challenging. I'll have to take a look at the code. Great tip. – Craig Ringer Nov 12 '14 at 4:38
  • Looks like it's in-process only, unfortunately, and can't be invoked via gdb or similar because it requires ptrace its self. So it's a bit like the debughelp DLL under Windows, rather than like a non-blocking gcore, but still very handy looking. I guess it'd be possible to use via an LD_PRELOAD hook and setup of a signal handler with gdb, detach, and signal the process, but it doesn't look like it's really designed to dump unmodified programs, and it has the issue shared by any in-process dump tool that if the process is messed up enough the dump won't work. – Craig Ringer Nov 12 '14 at 4:49
  • Sorry… I missed the "non-intrusive" bit when I first read the question. – EricM Nov 12 '14 at 6:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.