2 This file is part of GNUnet
3 Copyright (C) 2010 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * @file contrib/timeout_watchdog.c
21 * @brief small tool starting a child process, waiting that it terminates or killing it after a given timeout period
22 * @author Matthias Wachs
25 #include <sys/types.h>
36 sigchld_handler (int val)
42 waitpid (child, &status, 0);
43 if (WIFEXITED (status) != 0)
45 ret = WEXITSTATUS (status);
46 printf ("Test process exited with result %u\n", ret);
48 if (WIFSIGNALED (status) != 0)
50 ret = WTERMSIG (status);
51 printf ("Test process was signaled %u\n", ret);
58 sigint_handler (int val)
75 ("arg 1: timeout in sec., arg 2: executable, arg<n> arguments\n");
79 timeout = atoi (argv[1]);
84 /* with getpgid() it does not compile, but getpgrp is the BSD version and working */
87 signal (SIGCHLD, sigchld_handler);
88 signal (SIGABRT, sigint_handler);
89 signal (SIGFPE, sigint_handler);
90 signal (SIGILL, sigint_handler);
91 signal (SIGINT, sigint_handler);
92 signal (SIGSEGV, sigint_handler);
93 signal (SIGTERM, sigint_handler);
98 /* int setpgrp(pid_t pid, pid_t pgid); is not working on this machine */
99 //setpgrp (0, pid_t gpid);
102 execvp (argv[2], &argv[2]);
108 printf ("Child processes were killed after timeout of %u seconds\n",
116 /* end of timeout_watchdog.c */