Add FS #10214. Initial commit of the original PDa code for the GSoC Pure Data plugin...
[kugel-rb.git] / apps / plugins / pdbox / PDa / src / s_watchdog.c
blob48309c16c4a7ec8ce9ecc0fc15967b120582f6b3
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");
48 /* Copyright (c) 1997-2000 Miller Puckette.
49 * For information on usage and redistribution, and for a DISCLAIMER OF ALL
50 * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
52 /* This file is compiled into the separate program, "pd-watchdog," which
53 tries to prevent Pd from locking up the processor if it's at realtime
54 priority. Linux only. Invoked from s_inter.c. */
56 #include <sys/time.h>
57 #include <sys/types.h>
58 #include <unistd.h>
59 #include <signal.h>
60 #include <stdio.h>
62 int main(int argc, char **argv)
64 int happy = 1;
65 while (1)
67 struct timeval timout;
68 fd_set readset;
69 if (happy)
71 timout.tv_sec = 5;
72 timout.tv_usec = 0;
74 else
76 timout.tv_sec = 2;
77 timout.tv_usec = 0;
79 FD_ZERO(&readset);
80 FD_SET(0, &readset);
81 select(1, &readset, 0, 0, &timout);
82 if (FD_ISSET(0, &readset))
84 char buf[100];
85 happy = 1;
86 if (read(0, &buf, 100) <= 0)
87 return (0);
88 else continue;
90 happy = 0;
91 kill(getppid(), SIGHUP);
92 fprintf(stderr, "watchdog: signaling pd...\n");