Advertisement
leticiaf

Example

Jan 23rd, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.72 KB | None | 0 0
  1. #include <signal.h>
  2. #include <stdio.h>
  3. #include <wait.h>
  4.  
  5.  
  6. int counter = 0;
  7. int pid;
  8.  
  9.  
  10. void handler (int sig) {
  11. /*  counter++;
  12.     printf ("pid do handler= %d, counter= %d \n", getpid(), counter);
  13.     sleep(1);*/
  14.     return;
  15. }
  16.  
  17.  
  18. int main() {
  19.     int i;
  20.     int status;
  21.  
  22.     signal(SIGUSR2, handler);
  23.  
  24.     if (fork()==0){
  25.         for (i=0;i<5;i++) {
  26.             kill (getppid(), SIGUSR2);
  27.             printf("sent SIGUSR2 to parent\n");
  28.             WSTOPSIG(1);
  29.             sleep (2);
  30.         }
  31.         exit(0);
  32.     }
  33.  
  34.     /*while ((pid = waitpid(-1, &status, 0) ) > 0 ) {
  35.         if (..............................) printf("pai esperou por filho %d parado pelo sinal %d\n",
  36.         pid, ..........................................);
  37.         ......................................);
  38.     }*/
  39. //  exit(0);
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement