tst-signal.c 709 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include <signal.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. int win = 0;
  6. static void
  7. handler (int sig)
  8. {
  9. printf ("Received signal %d (%s).\n", sig, strsignal(sig));
  10. win = 1;
  11. }
  12. int
  13. main (void)
  14. {
  15. if (signal (SIGTERM, handler) == SIG_ERR)
  16. {
  17. perror ("signal: SIGTERM");
  18. exit (EXIT_FAILURE);
  19. }
  20. puts ("Set handler.");
  21. printf ("Sending myself signal %d.\n", SIGTERM);
  22. fflush (stdout);
  23. if (raise (SIGTERM) < 0)
  24. {
  25. perror ("raise: SIGTERM");
  26. exit (EXIT_FAILURE);
  27. }
  28. if (!win)
  29. {
  30. puts ("Didn't get any signal. Test FAILED!");
  31. exit (EXIT_FAILURE);
  32. }
  33. puts ("Got a signal. Test succeeded.");
  34. return EXIT_SUCCESS;
  35. }