Add the identifying header
[kugel-rb.git] / apps / plugins / pdbox / PDa / src / s_watchdog.c
blobe8653e9e396d4528fcd91bc31a22ea62bb0f6ad2
1 /* Copyright (c) 1997-2000 Miller Puckette.
2 * For information on usage and redistribution, and for a DISCLAIMER OF ALL
3 * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
5 /* This file is compiled into the separate program, "pd-watchdog," which
6 tries to prevent Pd from locking up the processor if it's at realtime
7 priority. Linux only. Invoked from s_inter.c. */
9 #include <sys/time.h>
10 #include <sys/types.h>
11 #include <unistd.h>
12 #include <signal.h>
13 #include <stdio.h>
15 int main(int argc, char **argv)
17 int happy = 1;
18 while (1)
20 struct timeval timout;
21 fd_set readset;
22 if (happy)
24 timout.tv_sec = 5;
25 timout.tv_usec = 0;
27 else
29 timout.tv_sec = 2;
30 timout.tv_usec = 0;
32 FD_ZERO(&readset);
33 FD_SET(0, &readset);
34 select(1, &readset, 0, 0, &timout);
35 if (FD_ISSET(0, &readset))
37 char buf[100];
38 happy = 1;
39 if (read(0, &buf, 100) <= 0)
40 return (0);
41 else continue;
43 happy = 0;
44 kill(getppid(), SIGHUP);
45 fprintf(stderr, "watchdog: signaling pd...\n");