pause.c 451 B

123456789101112131415161718192021222324252627
  1. #include <assert.h>
  2. #include <errno.h>
  3. #include <signal.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <unistd.h>
  7. void handler(int signal)
  8. {
  9. printf("hello world\n");
  10. }
  11. int main(int argc, char ** argv)
  12. {
  13. if (signal(SIGALRM, &handler) < 0)
  14. return EXIT_FAILURE;
  15. if (alarm(1) < 0)
  16. return EXIT_FAILURE;
  17. int ret = pause();
  18. assert(ret == -1);
  19. assert(errno == EINTR);
  20. printf("good bye\n");
  21. return 0;
  22. }