Advertisement
Guest User

nebunie tema

a guest
Apr 19th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <sys/wait.h>
  3. #include <sys/wait.h>
  4. #include <time.h>
  5. #include "hdr.h"
  6.  
  7. int main()
  8. {
  9. pid_t pid_tata;
  10. pid_t pid_fiu;
  11. pid_t pid_fii[4];
  12. pid_t stare;
  13. pid_tata=getpid();
  14. int i;
  15. for(i=0;i<4;i++)
  16. {
  17. pid_fii[i]=fork();
  18. if(pid_fii[i]<0)
  19. {
  20. // err_sys("nu a functionat fork-ul");
  21. }
  22. else if(pid_fii[i]==0)
  23. {
  24.  
  25. pid_tata=getppid();
  26. pid_fiu=getpid();
  27. sleep(8);
  28. for(i=0;i<10;i++)
  29. {
  30. printf("%d cu parintele %d\n",pid_fiu,pid_tata);
  31. }
  32. exit(1);
  33. }
  34. }
  35. for(i=0;i<10;i++)
  36. {
  37. printf("%d cu procesele fiu %d %d %d %d\n", pid_tata, pid_fii[0], pid_fii[1], pid_fii[2], pid_fii[3]);
  38. }
  39. while((pid_fiu=wait(NULL))!=-1)
  40. {
  41. printf("\n procesul terminat %d \n", pid_fiu);
  42. //print_exit(stare);
  43. }
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement