2 * $Id: timeout.c,v 1.3 2001-06-29 14:14:46 rufustfirefly Exp $
7 #endif /* HAVE_CONFIG_H */
16 #endif /* HAVE_UNISTD_H */
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) {
169 if (isdigit (*optarg)) {
170 whatsig = atoi (optarg);
172 for (i = 0; sigs[i].name; i++) {
173 if (!strcmp (sigs[i].name, optarg)) {
174 whatsig = sigs[i].num;
181 "%s: Unknown signal %s\n",
196 if (optind > argc - 2) {
201 if (!isdigit (*argv[optind])) {
202 fprintf (stderr, "%s: \"seconds\" must be numeric, not %s\n",
211 fprintf (stderr, "%s: fork failed: ", *av);
214 } else if (pid == 0) {
215 int seconds = atoi (argv[optind]);
223 while (seconds-- > 0) {
225 * too bad there's no SIGPARENT so we have to keep
226 * polling to find out if it's still there
229 if (kill (pid, 0) != 0)
238 execvp (argv[optind + 1], argv + optind + 1);
240 fprintf (stderr, "%s: can't execute ", *av);
241 perror (argv[optind + 1]);