Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <sys/types.h>
  4. #include <unistd.h>
  5. #include <signal.h>
  6. #include <sys/wait.h>
  7.  
  8. void oblsluga_zakonczenia_dziecka(int nr_sig)
  9. {
  10. printf("Rodzic już się dowiedział o zakończeniu procesu %d\n",wait(NULL));
  11.  
  12. }
  13. int main()
  14. {
  15. signal(SIGCHLD,oblsluga_zakonczenia_dziecka);
  16. int childpid;
  17. //int status=1;
  18. //int zakonczono;
  19. printf("startuje proces macierzysty pid %d\n",getpid());
  20. if ((childpid = fork()) == -1)
  21. {
  22. perror("nie moge forknac");
  23. exit(1);
  24. }
  25. else
  26. if (childpid ==0 )
  27. {
  28.  
  29. printf("Proces potomny o pidzie %d z rodzica %d\n",getpid(),getppid());
  30. }
  31. else
  32. {
  33. sleep(10);
  34. printf("Proces macierzysty o pidzie %d i dziecku %d\n",getpid(),childpid);
  35. }
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement