Advertisement
STANAANDREY

linux handle sigusr1 signal

Nov 2nd, 2024
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.46 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <signal.h>
  4. #include <unistd.h>
  5. #include <string.h>
  6.  
  7. void handleSigusr1() {
  8.     puts("Received SIGUSR1");
  9. }
  10.  
  11. int main(int argc, char *argv[]) {
  12.     struct sigaction sa;
  13.     memset(&sa, 0, sizeof(struct sigaction));
  14.     sa.sa_handler = &handleSigusr1;
  15.     if (sigaction(SIGUSR1, &sa, NULL)) {
  16.         perror("sigaction");
  17.         exit(1);
  18.     }
  19.     while (1) {
  20.         sleep(1);
  21.     }
  22.     return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement