Advertisement
Guest User

Untitled

a guest
Dec 17th, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. for(x = 0; x <2 ; x++)
  2. {
  3. pid2 = fork();
  4. if(pid2 == -1)
  5. {
  6. perror("Error fork hijo.\n");
  7. exit(-1);
  8. }else if (pid2 == 0)
  9. {
  10. for (y = 0; y <3 ; y++ )
  11. {
  12. printf("Soy un hijo\n");
  13. pidSons = fork();
  14. if(pidSons == -1)
  15. {
  16. perror("Error fork nieto.\n");
  17. exit(-1);
  18.  
  19. }else if(pidSons == 0)
  20. {
  21. printf("Soy un nieto\n");
  22. srand(getpid());
  23. sleep(wait_time());
  24. exit(binOut());
  25.  
  26. } else if (pidSons > 0)
  27. {
  28. waitpid(pidSons,&status2, 0);
  29. enfermo = WEXITSTATUS(status2);
  30. exit(enfermo);
  31. }
  32.  
  33. }
  34. } else
  35. {
  36. waitpid(pid2, &status3, 0);
  37. enfermo2 = WEXITSTATUS(status3);
  38. sumaenfermos += enfermo2;
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement