Advertisement
Guest User

Untitled

a guest
Nov 9th, 2016
123
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.  
  7. void f_parent()
  8. {
  9.   printf("Ping\n");
  10. }
  11. void f_child()
  12. {
  13.   printf("Pong\n");
  14. }
  15.  
  16. int main()
  17. {
  18.   pid_t pid;
  19.   pid = fork();
  20.   if(pid < 0)
  21.     {
  22.       perror("Fork error: ");
  23.       exit(1);
  24.     }
  25.   else if(pid == 0)
  26.     {
  27.       signal(SIGUSR2, f_child);
  28.       kill(getpid(), SIGUSR2);
  29.     }
  30.   else
  31.     {
  32.       signal(SIGUSR1, f_parent);
  33.       kill(getpid(), SIGUSR1);
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement