Advertisement
Guest User

Untitled

a guest
May 21st, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <fcntl.h>
  4. #include <stdlib.h>
  5. #include <sys/types.h>
  6. #include <sys/wait.h>
  7. #include <signal.h>
  8.  
  9. void myfunc(int signum){
  10. printf("in handler\n");
  11. exit(0);
  12. }
  13.  
  14. void main()
  15. {
  16. pid_t pid;
  17. int n;
  18. if((pid = fork()) == 0){
  19. signal(SIGUSR1, myfunc);
  20. pause();
  21. printf("child pid is %d and parent is %d\n", getpid(), getppid());
  22. }
  23. else{
  24.  
  25. printf("parent pid is %d\n", getpid());
  26. printf("child pid is %d\n", pid);
  27. kill(pid, SIGUSR1);
  28. wait(NULL);
  29. }
  30. exit(0);
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement