SHARE
TWEET

Untitled

Sbovvo Feb 21st, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <signal.h>
  4. #include <unistd.h>
  5. #include <sys/wait.h>
  6.  
  7. void sig1(int sig){
  8. printf("Sono la prima funzione, PID del padre=%d, ho ricevuto SIGUSR1\n", getpid());
  9. }
  10.  
  11. void sig2(int sig){
  12.     printf("Sono la deconda funziona , PID del figio=%d, ho ricevuto SIGUSR2\n",getpid());
  13. }
  14.  
  15. int main(void){
  16.     pid_t pid;
  17.     int i;
  18.    
  19.     signal(SIGUSR2, sig1);
  20.     signal(SIGUSR1, sig2);
  21.    
  22.     pid=fork();
  23.    
  24.     switch(pid){
  25.         case -1:
  26.             perror("Errore sei sterile\n");
  27.             exit(EXIT_FAILURE);
  28.             break;
  29.         case 0:
  30.             while(i>0){
  31.                 kill(getppid(),SIGUSR2);
  32.                 i--;
  33.             }
  34.             exit(EXIT_SUCCESS);
  35.         default:
  36.             while(i>0){
  37.                 kill(getppid(),SIGUSR1);
  38.                 i--;
  39.             }
  40.             exit(EXIT_SUCCESS);
  41.     }
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top