1 /* dumpcore - create core file of running process */
5 #include <minix/config.h>
6 #include <minix/type.h>
8 #include <minix/const.h>
9 #include <sys/ptrace.h>
18 #include <machine/archtypes.h>
19 #include "kernel/proc.h"
21 #define CLICK_WORDS (CLICK_SIZE / sizeof(unsigned long))
23 int main(int argc
, char *argv
[])
29 printf("usage: %s <pid>\n", argv
[0]);
35 if (ptrace(T_ATTACH
, pid
, 0, 0) != 0) {
36 perror("ptrace(T_ATTACH)");
40 if (waitpid(pid
, &status
, 0) != pid
) {
45 while (WIFSTOPPED(status
) && WSTOPSIG(status
) != SIGSTOP
) {
46 /* whatever happens here is fine */
47 ptrace(T_RESUME
, pid
, 0, WSTOPSIG(status
));
49 if (waitpid(pid
, &status
, 0) != pid
) {
55 if (!WIFSTOPPED(status
)) {
56 fprintf(stderr
, "process died while attaching\n");
60 if (ptrace(T_DUMPCORE
, pid
, 0, 0) != 0) {
61 fprintf(stderr
, "warning, dumpcore failed (%s)\n",
65 if (ptrace(T_DETACH
, pid
, 0, 0)) {
66 fprintf(stderr
, "warning, detaching failed (%s)\n",