rickg@toshiba.tic.oz.au (Rick Gunderson) (08/07/90)
I'm sure that there must be a way to get a process to dump a core image of itself. I've been trying to use the ptrace(2) call with the SunOS extensions of PTRACE_ATTACH, PTRACE_DUMPCORE and PTRACE_DETACH, but I can't get it to work properly. Below is a code fragment that I've been trying to use to get a process to dump its core image. It gets as far as line 14 where it actually makes the file, but puts nothing in it. 1 switch (child_pid = fork()) 2 { 3 case -1: 4 exit(1); 5 6 case 0: 7 for (;;) /* child just loops */ 8 ; 9 break; 10 11 default: 12 ptrace(PTRACE_ATTACH, child_pid, ...); 13 wait4(child_pid, ...); 14 ptrace(PTRACE_DUMPCORE, child_pid, "corefile", ...); 15 ptrace(PTRACE_DETACH, child_pid, ...); 16 } It works okay if I forget about the fork and just specify the pid of an existing process, but what I want is for a program to be able to dump itself. Perhaps I'm going about this all wrong. If anyone out there in Net Land has any ideas on this, I'd appreciate hearing them. Thanks, Rick = Rick Gunderson ACSnet: rickg@toshiba.tic.oz = = Toshiba International Corp. Internet: rickg%toshiba.tic.oz@munnari.oz.au = = Sydney, Australia Phone: 61-2-428-2077 Fax: 61-2-427-7405 = = Snail: Private Bag 29, Lane Cove, NSW, Australia 2066 =