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
|
169
|
24 int
|
|
25 main (int argc, char *argv[])
|
0
|
26 {
|
|
27 int period = 60;
|
|
28
|
|
29 if (argc > 1)
|
|
30 period = atoi (argv[1]);
|
|
31
|
|
32 while (1)
|
|
33 {
|
|
34 /* Make sure wakeup stops when Emacs goes away. */
|
|
35 if (getppid () == 1)
|
169
|
36 return 0;
|
0
|
37 printf ("Wake up!\n");
|
|
38 fflush (stdout);
|
|
39 /* If using a period of 60, produce the output when the minute
|
|
40 changes. */
|
|
41 if (period == 60)
|
|
42 {
|
169
|
43 time_t when;
|
|
44 struct tm *tp;
|
0
|
45 time (&when);
|
|
46 tp = localtime (&when);
|
|
47 sleep (60 - tp->tm_sec);
|
|
48 }
|
|
49 else
|
|
50 sleep (period);
|
|
51 }
|
|
52 }
|