Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<unistd.h>
  4. #include<sys/types.h>
  5. #include<sys/wait.h>
  6.  
  7.  
  8. void do_child_work(void)
  9. {
  10. puts("Jestem potomkiem.");
  11. printf("Pid procesu biezacego czyli dziecka %d\n Pid jego rodzica %d\N",getpid(),getppid());
  12. exit(0);
  13. }
  14.  
  15. void do_parent_work(int pid)
  16. {
  17. puts("Jestem rodzicem.");
  18. printf("Pid procesu biezacego czyli rodzica %d\n Pid dziecka %d\n",getpid(),pid);
  19. if(wait(0)<0)
  20. perror("wait");
  21. }
  22.  
  23. int main(void)
  24. {
  25. int pid = fork();
  26. if(pid<0)
  27. perror("fork");
  28. if(pid==0)
  29. do_child_work();
  30. else
  31. do_parent_work();
  32. return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement