signal.c 538 B

12345678910111213141516171819202122232425
  1. #include <signal.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. #include <errno.h>
  6. #include "test_helpers.h"
  7. void handler(int sig) {
  8. puts("Signal handler called!");
  9. }
  10. int main(void) {
  11. void (*signal_status)(int) = signal(SIGUSR1, handler);
  12. ERROR_IF(signal, signal_status, == SIG_ERR);
  13. signal_status = signal(SIGUSR1, handler);
  14. ERROR_IF(signal, signal_status, != handler);
  15. puts("Raising...");
  16. int raise_status = raise(SIGUSR1);
  17. ERROR_IF(raise, raise_status, < 0);
  18. puts("Raised.");
  19. }