10 static int caught = 0;
12 static void caught_signal(
int which)
17 static int wait_for_process(pid_t pid)
24 sig_handler.sa_handler = caught_signal;
25 sig_handler.sa_flags = 0;
35 pid_t p = waitpid(pid, &stats, 0);
38 rv = WIFEXITED(stats) ?
40 (0x80 | WTERMSIG(stats));
47 sig = caught > 0 ? caught : SIGTERM;
48 if (caught == SIGALRM) {
49 fprintf(stderr,
"Timeout.. killing the process\n");
59 if (
kill(pid, sig) < 0) {
61 perror(
"lost child when trying to kill");
70 static int spawn_and_wait(
int argc,
char **argv)
83 execvp(argv[0], argv);
88 rv = wait_for_process(pid);
93 int main(
int argc,
char **argv)
98 naptime = atoi(argv[1]);
103 return spawn_and_wait(argc+2, argv+2);