| 1 | /* Program to produce output at regular intervals. */ |
| 2 | |
| 3 | #include <config.h> |
| 4 | |
| 5 | #include <stdio.h> |
| 6 | #include <sys/types.h> |
| 7 | |
| 8 | #ifdef TIME_WITH_SYS_TIME |
| 9 | #include <sys/time.h> |
| 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 |
| 18 | |
| 19 | struct tm *localtime (); |
| 20 | |
| 21 | main (argc, argv) |
| 22 | int argc; |
| 23 | char **argv; |
| 24 | { |
| 25 | int period = 60; |
| 26 | time_t when; |
| 27 | struct tm *tp; |
| 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) |
| 36 | exit (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 | { |
| 43 | time (&when); |
| 44 | tp = localtime (&when); |
| 45 | sleep (60 - tp->tm_sec); |
| 46 | } |
| 47 | else |
| 48 | sleep (period); |
| 49 | } |
| 50 | } |