3 #include <sys/ptrace.h>
6 #define die(msg) { perror(msg); exit(EXIT_FAILURE); }
9 main(int argc
, char *argv
[])
11 int pid
, c
, rc
, status
;
12 struct timeval tv
, tv2
;
15 printf("no enough args\n");
22 } else if (pid
== 0) {
23 if (ptrace(PTRACE_TRACEME
, 0, (char *) 1, 0) == -1) die("trace me");
24 if (kill(getpid(), SIGSTOP
) == -1) die("stop");
26 execvp(argv
[1], NULL
);
28 execvp(argv
[1], &argv
[2]);
36 gettimeofday(&tv
, NULL
);
37 rc
= ptrace(PTRACE_SYSCALL
, pid
, (char *) 1, 0);
38 if (rc
== -1) die("trace syscall");
41 rc
= waitpid(pid
, &status
, 0);
42 if (rc
== -1) die("waitpid");
44 gettimeofday(&tv2
, NULL
);
46 if (WIFEXITED(status
)) break;
48 fprintf(stderr
, "%03d: %07.5lf\n", c
, (tv2
.tv_sec
- tv
.tv_sec
) + (tv2
.tv_usec
- tv
.tv_usec
) / 1E6
);