home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / emx / test / alarm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-02  |  1.0 KB  |  53 lines

  1. /* alarm.c (emx+gcc) */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <signal.h>
  7.  
  8. static void usage (void)
  9. {
  10.   fputs ("Usage: alarm [-sw]\n", stderr);
  11.   exit (1);
  12. }
  13.  
  14.  
  15. static void handler (int sig)
  16. {
  17.   printf ("Signal %d received. Process stopped.\n", sig);
  18.   exit (1);
  19. }
  20.  
  21.  
  22. int main (int argc, char *argv[])
  23. {
  24.   int c, wait_flag, sleep_flag;
  25.  
  26.   wait_flag = 0; sleep_flag = 0;
  27.   if (argc == 2 && strcmp (argv[1], "-w") == 0)
  28.     wait_flag = 1;
  29.   else if (argc == 2 && strcmp (argv[1], "-s") == 0)
  30.     sleep_flag = 1;
  31.   else if (argc != 1)
  32.     usage ();
  33.   signal (SIGALRM, handler);
  34.   alarm (4);
  35.   if (sleep_flag)
  36.     printf ("sleep(10): %d\n", sleep (10));
  37.   else if (wait_flag)
  38.     for (;;)
  39.       ;
  40.   else
  41.     for (;;)
  42.       {
  43.         c = _read_kbd (0, 0, 0);
  44.         if (c == 0)
  45.           _read_kbd (0, 1, 0);
  46.         else if (c == 0x1b)
  47.           break;
  48.         else if (c >= '0' && c <= '9')
  49.           printf ("alarm=%d\n", alarm (c - '0'));
  50.       }
  51.   return (0);
  52. }
  53.