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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @file src/util/gnunet-timeout.c
23 * @brief small tool starting a child process, waiting that it terminates or killing it after a given timeout period
24 * @author Matthias Wachs
27 #include <sys/types.h>
38 sigchld_handler (int val)
47 if (WIFEXITED (status) != 0)
49 ret = WEXITSTATUS (status);
51 "Process exited with result %u\n",
53 exit (ret); /* return same status code */
55 if (WIFSIGNALED (status) != 0)
57 ret = WTERMSIG (status);
59 "Process received signal %u\n",
62 ret); /* kill self with the same signal */
69 sigint_handler (int val)
87 "arg 1: timeout in sec., arg 2: executable, arg<n> arguments\n");
91 timeout = atoi (argv[1]);
96 /* with getpgid() it does not compile, but getpgrp is the BSD version and working */
99 signal (SIGCHLD, sigchld_handler);
100 signal (SIGABRT, sigint_handler);
101 signal (SIGFPE, sigint_handler);
102 signal (SIGILL, sigint_handler);
103 signal (SIGINT, sigint_handler);
104 signal (SIGSEGV, sigint_handler);
105 signal (SIGTERM, sigint_handler);
110 /* int setpgrp(pid_t pid, pid_t pgid); is not working on this machine */
111 //setpgrp (0, pid_t gpid);
121 printf ("Child processes were killed after timeout of %u seconds\n",
130 /* end of timeout_watchdog.c */