kernel: restore setting KTS_NONE
[minix.git] / commands / dumpcore / dumpcore.c
blobca6b70bc62229dc87691174aa37f97d77640a91c
1 /* dumpcore - create core file of running process */
3 #include <fcntl.h>
4 #include <unistd.h>
5 #include <minix/config.h>
6 #include <minix/type.h>
7 #include <minix/ipc.h>
8 #include <minix/const.h>
9 #include <sys/ptrace.h>
10 #include <sys/wait.h>
11 #include <signal.h>
12 #include <timers.h>
13 #include <errno.h>
14 #include <stdio.h>
15 #include <string.h>
16 #include <stdlib.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[])
25 pid_t pid;
26 int r, status;
28 if(argc != 2) {
29 printf("usage: %s <pid>\n", argv[0]);
30 return 1;
33 pid = atoi(argv[1]);
35 if (ptrace(T_ATTACH, pid, 0, 0) != 0) {
36 perror("ptrace(T_ATTACH)");
37 return 1;
40 if (waitpid(pid, &status, 0) != pid) {
41 perror("waitpid");
42 return 1;
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) {
50 perror("waitpid");
51 return 1;
55 if (!WIFSTOPPED(status)) {
56 fprintf(stderr, "process died while attaching\n");
57 return 1;
60 if (ptrace(T_DUMPCORE, pid, 0, 0) != 0) {
61 fprintf(stderr, "warning, dumpcore failed (%s)\n",
62 strerror(errno));
65 if (ptrace(T_DETACH, pid, 0, 0)) {
66 fprintf(stderr, "warning, detaching failed (%s)\n",
67 strerror(errno));
70 return r;