0
|
1 /* Program to produce output at regular intervals. */
|
|
2
|
|
3 #include <../src/config.h>
|
|
4
|
|
5 #if __STDC__ || defined(STDC_HEADERS)
|
|
6 #include <stdlib.h>
|
|
7 #include <unistd.h>
|
|
8 #endif
|
|
9
|
|
10 #include <stdio.h>
|
|
11 #include <sys/types.h>
|
|
12
|
|
13 #ifdef TIME_WITH_SYS_TIME
|
|
14 #include <sys/time.h>
|
|
15 #include <time.h>
|
|
16 #else
|
|
17 #ifdef HAVE_SYS_TIME_H
|
|
18 #include <sys/time.h>
|
|
19 #else
|
|
20 #include <time.h>
|
|
21 #endif
|
|
22 #endif
|
|
23
|
|
24 void
|
|
25 main (argc, argv)
|
|
26 int argc;
|
|
27 char **argv;
|
|
28 {
|
|
29 int period = 60;
|
|
30 time_t when;
|
|
31 struct tm *tp;
|
|
32
|
|
33 if (argc > 1)
|
|
34 period = atoi (argv[1]);
|
|
35
|
|
36 while (1)
|
|
37 {
|
|
38 /* Make sure wakeup stops when Emacs goes away. */
|
|
39 if (getppid () == 1)
|
|
40 exit (0);
|
|
41 printf ("Wake up!\n");
|
|
42 fflush (stdout);
|
|
43 /* If using a period of 60, produce the output when the minute
|
|
44 changes. */
|
|
45 if (period == 60)
|
|
46 {
|
|
47 time (&when);
|
|
48 tp = localtime (&when);
|
|
49 sleep (60 - tp->tm_sec);
|
|
50 }
|
|
51 else
|
|
52 sleep (period);
|
|
53 }
|
|
54 }
|