1 /* run a command with a limited timeout
2 tridge@samba.org, June 2005
4 attempt to be as portable as possible (fighting posix all the way)
12 #include <sys/types.h>
15 static void usage(void)
17 printf("usage: timelimit <time> <command>\n");
20 static void sig_alrm(int sig)
22 fprintf(stderr, "\nMaximum time expired in timelimit - killing\n");
27 int main(int argc, char *argv[])
37 if (setpgrp(0,0) == -1) {
42 if (setpgrp() == -1) {
48 maxtime = atoi(argv[1]);
49 signal(SIGALRM, sig_alrm);
53 execvp(argv[2], argv+2);
60 pid_t pid = wait(&status);
62 ret = WEXITSTATUS(status);
63 } else if (errno == ECHILD) {