aboutsummaryrefslogtreecommitdiff
path: root/pd/src/s_watchdog.c
diff options
context:
space:
mode:
authorGuenter Geiger <ggeiger@users.sourceforge.net>2002-07-29 17:06:19 +0000
committerGuenter Geiger <ggeiger@users.sourceforge.net>2002-07-29 17:06:19 +0000
commit57045df5fe3ec557e57dc7434ac1a07b5521bffc (patch)
tree7174058b41b73c808107c7090d9a4e93ee202341 /pd/src/s_watchdog.c
parentda38b3424229e59f956252c3d89895e43e84e278 (diff)
This commit was generated by cvs2svn to compensate for changes in r58,
which included commits to RCS files with non-trunk default branches. svn path=/trunk/; revision=59
Diffstat (limited to 'pd/src/s_watchdog.c')
-rw-r--r--pd/src/s_watchdog.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/pd/src/s_watchdog.c b/pd/src/s_watchdog.c
new file mode 100644
index 00000000..a2122824
--- /dev/null
+++ b/pd/src/s_watchdog.c
@@ -0,0 +1,47 @@
+/* Copyright (c) 1997-2000 Miller Puckette.
+* For information on usage and redistribution, and for a DISCLAIMER OF ALL
+* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
+
+/* This file is compiled into the separate program, "pd-watchdog," which
+tries to prevent Pd from locking up the processor if it's at realtime
+priority. Linux only. Invoked from s_inter.c. */
+
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <signal.h>
+#include <stdio.h>
+
+int main(int argc, char **argv)
+{
+ int happy = 1;
+ while (1)
+ {
+ struct timeval timout;
+ fd_set readset;
+ if (happy)
+ {
+ timout.tv_sec = 5;
+ timout.tv_usec = 0;
+ }
+ else
+ {
+ timout.tv_sec = 2;
+ timout.tv_usec = 0;
+ }
+ FD_ZERO(&readset);
+ FD_SET(0, &readset);
+ select(1, &readset, 0, 0, &timout);
+ if (FD_ISSET(0, &readset))
+ {
+ char buf[100];
+ happy = 1;
+ if (read(0, &buf, 100) <= 0)
+ return (0);
+ else continue;
+ }
+ happy = 0;
+ kill(getppid(), SIGHUP);
+ fprintf(stderr, "watchdog: signaling pd...\n");
+ }
+}