home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / emacs-19.16 / lib-src / wakeup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-07  |  703 b   |  40 lines

  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. }
  40.