Advertisement
Guest User

Untitled

a guest
Nov 9th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <signal.h>
  4. #include <sys/types.h>
  5. #include <stdlib.h>
  6. #include <sys/wait.h>
  7.  
  8. void f_parent()
  9. {
  10.   printf("Ping\n");
  11. }
  12. void f_child()
  13. {
  14.   printf("Pong\n");
  15. }
  16.  
  17. int main()
  18. {
  19.   pid_t pid; int stat;
  20.   pid = fork();
  21.   if(pid < 0) // ERROR
  22.     {
  23.       perror("Fork error: ");
  24.       exit(1);
  25.     }
  26.   else if(pid == 0) // CHILD
  27.     {
  28.       signal(SIGUSR2, f_child);
  29.       kill(getpid(), SIGUSR2);
  30.     }
  31.   else // PARENT
  32.     {
  33.       signal(SIGUSR1, f_parent);
  34.       kill(getpid(), SIGUSR1);
  35.       wait(&stat);
  36.       kill(pid, SIGUSR2);
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement