Advertisement
Guest User

Untitled

a guest
Dec 5th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1.  
  2.  
  3. #include<stdio.h>
  4. #include<sys/types.h>
  5. #include<sys/signal.h>
  6.  
  7. void traitement (int sig)
  8. {
  9. int i =0;
  10. if(sig = SIGUSR1) { printf("Signal SIGUSR1 recu\n"); i++; }
  11. else if(sig = SIGUSR2){ printf("Signal SIGUSR2 recu \n");i--;}
  12. else{
  13. printf("signal SIGINT reçu !\n");
  14. }
  15. }
  16.  
  17. int main(int arg , char*argv[])
  18. {
  19. struct sigaction action;
  20. sigset_t masque;
  21. int val[] = {1,2,3,4,5,6,7,8};
  22. int i =0;
  23. sigemptyset(&masque);
  24. action.sa_handler = traitement;
  25. action.sa_mask = masque;
  26. action.sa_flags = 0;
  27.  
  28.  
  29.  
  30. sigaction(SIGUSR1,&action,NULL);
  31. sigaction(SIGUSR2,&action,NULL);
  32. printf("Mon pid est %d\n",getpid());
  33. while(1) { printf("%u", val[i]); kill(argv[1],10); kill(argv[2],12);
  34. }
  35.  
  36. sigfillset(&masque);
  37. sigdelset(&masque,SIGINT);
  38.  
  39. sigdelset(&masque, SIGUSR2);
  40. sigsuspend(&masque);
  41.  
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement