Commit | Line | Data |
---|---|---|
58fd8a81 DM |
1 | /* Program to produce output at regular intervals. */ |
2 | ||
18160b98 | 3 | #include <config.h> |
af40bbfa | 4 | |
58fd8a81 | 5 | #include <stdio.h> |
11e5be7d | 6 | #include <sys/types.h> |
af40bbfa JB |
7 | |
8 | #ifdef TIME_WITH_SYS_TIME | |
2198e8fe | 9 | #include <sys/time.h> |
af40bbfa JB |
10 | #include <time.h> |
11 | #else | |
12 | #ifdef HAVE_SYS_TIME_H | |
13 | #include <sys/time.h> | |
14 | #else | |
15 | #include <time.h> | |
16 | #endif | |
17 | #endif | |
58fd8a81 DM |
18 | |
19 | struct tm *localtime (); | |
20 | ||
21 | main (argc, argv) | |
22 | int argc; | |
23 | char **argv; | |
24 | { | |
25 | int period = 60; | |
1da14ffd | 26 | time_t when; |
58fd8a81 DM |
27 | struct tm *tp; |
28 | ||
29 | if (argc > 1) | |
30 | period = atoi (argv[1]); | |
31 | ||
32 | while (1) | |
33 | { | |
7fb0d26f JB |
34 | /* Make sure wakeup stops when Emacs goes away. */ |
35 | if (getppid () == 1) | |
36 | exit (0); | |
58fd8a81 DM |
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 | { | |
43 | time (&when); | |
44 | tp = localtime (&when); | |
45 | sleep (60 - tp->tm_sec); | |
46 | } | |
47 | else | |
48 | sleep (period); | |
49 | } | |
50 | } |