]> code.delx.au - gnu-emacs/blob - lib-src/wakeup.c
* wakeup.c: Include sys/types.h, too; I think that's where time_t
[gnu-emacs] / lib-src / wakeup.c
1 /* Program to produce output at regular intervals. */
2
3 #include <stdio.h>
4 #include <time.h>
5 #include <sys/types.h>
6 #include <sys/time.h>
7
8 struct tm *localtime ();
9
10 main (argc, argv)
11 int argc;
12 char **argv;
13 {
14 int period = 60;
15 time_t when;
16 struct tm *tp;
17
18 if (argc > 1)
19 period = atoi (argv[1]);
20
21 while (1)
22 {
23 /* Make sure wakeup stops when Emacs goes away. */
24 if (getppid () == 1)
25 exit (0);
26 printf ("Wake up!\n");
27 fflush (stdout);
28 /* If using a period of 60, produce the output when the minute
29 changes. */
30 if (period == 60)
31 {
32 time (&when);
33 tp = localtime (&when);
34 sleep (60 - tp->tm_sec);
35 }
36 else
37 sleep (period);
38 }
39 }