Advertisement
Tobiahao

S01_LAB01_11

Nov 12th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.60 KB | None | 0 0
  1. /*
  2. Pokaż w jaki sposób sygnały mogą być przez proces blokowane lub ignorowane.
  3. */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <unistd.h>
  8. #include <signal.h>
  9. #include <wait.h>
  10.  
  11. int main(void)
  12. {
  13.     pid_t pid;
  14.     if(signal(SIGINT, SIG_IGN) == SIG_ERR){
  15.         perror("signal");
  16.         return EXIT_FAILURE;
  17.     }
  18.  
  19.     pid = fork();
  20.     if(pid == -1){
  21.         perror("fork");
  22.         return EXIT_FAILURE;
  23.     }
  24.     else if(pid == 0){
  25.         kill(getppid(), SIGINT);       
  26.     }
  27.     else{
  28.         wait(NULL);
  29.         printf("Sygnal SIGINT jest ignorowany, koniec programu za 3 sekundy\n");
  30.         sleep(3);
  31.         printf("\n");
  32.     }
  33.  
  34.     return EXIT_SUCCESS;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement