11 main (int argc, char *argv[])
13 const char *program_name = argv[0];
19 "setitimer-helper: runs a program with a virtual CPU limit\n"
20 "usage: %s TIMEOUT PROGRAM [ARG...]\n"
21 " where TIMEOUT is the virtual CPU limit, in seconds,\n"
22 " and remaining arguments specify the program to run\n"
23 " and its argument.\n",
28 timeout = strtod (argv[1], NULL);
29 if (timeout >= 0.0 && timeout < LONG_MAX)
33 it.it_interval.tv_sec = 0;
34 it.it_interval.tv_usec = 0;
35 it.it_value.tv_sec = timeout;
36 it.it_value.tv_usec = (timeout - floor (timeout)) * 1000000;
37 if (setitimer (ITIMER_VIRTUAL, &it, NULL) < 0)
38 fprintf (stderr, "%s: setitimer: %s\n",
39 program_name, strerror (errno));
42 fprintf (stderr, "%s: invalid timeout value \"%s\"\n",
43 program_name, argv[1]);
45 execvp (argv[2], &argv[2]);
46 fprintf (stderr, "%s: couldn't exec \"%s\": %s\n",
47 program_name, argv[2], strerror (errno));