2 * $Id: timeout.c,v 1.5 2005-04-28 20:49:36 bfernhomberg Exp $
7 #endif /* HAVE_CONFIG_H */
16 #endif /* HAVE_UNISTD_H */
106 { "VTALRM", SIGVTALRM },
112 { "WINCH", SIGWINCH },
134 fprintf (stderr, "Usage: %s [-s signal] seconds program [args]\n\n",
136 fprintf (stderr, "You can use a numerical signal, or one of these:\n");
140 for (i = 0; sigs[i].name; i++) {
142 fprintf (stderr, "\n\t");
144 fprintf (stderr, "%s", sigs[i].name);
146 if ((i + 1) % COLS != 0)
147 fprintf (stderr, "\t");
150 fprintf (stderr, "\n\n");
159 int whatsig = SIGTERM;
166 while ((i = getopt (argc, argv, "+s:")) != -1) {
170 if (isdigit (*optarg)) {
171 whatsig = atoi (optarg);
173 for (i = 0; sigs[i].name; i++) {
174 if (!strcmp (sigs[i].name, optarg)) {
175 whatsig = sigs[i].num;
182 "%s: Unknown signal %s\n",
197 if (optind > argc - 2) {
202 if (!isdigit (*argv[optind])) {
203 fprintf (stderr, "%s: \"seconds\" must be numeric, not %s\n",
212 fprintf (stderr, "%s: fork failed: ", *av);
215 } else if (pid == 0) {
216 int seconds = atoi (argv[optind]);
224 while (seconds-- > 0) {
226 * too bad there's no SIGPARENT so we have to keep
227 * polling to find out if it's still there
230 if (kill (pid, 0) != 0)
239 execvp (argv[optind + 1], argv + optind + 1);
241 fprintf (stderr, "%s: can't execute ", *av);
242 perror (argv[optind + 1]);