pause.c 450 B

12345678910111213141516171819202122232425
  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. printf("hello world\n");
  9. }
  10. int main(int argc, char** argv) {
  11. if (signal(SIGALRM, &handler) < 0)
  12. return EXIT_FAILURE;
  13. if (alarm(1) < 0)
  14. return EXIT_FAILURE;
  15. int ret = pause();
  16. assert(ret == -1);
  17. assert(errno == EINTR);
  18. printf("good bye\n");
  19. return 0;
  20. }