Advertisement
Guest User

trab1-so

a guest
Nov 13th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <unistd.h>
  4.  
  5. int main()
  6. {
  7.  
  8. pid_t idPA;
  9. pid_t idPB;
  10. pid_t idPB1;
  11. pid_t idPB2;
  12. pid_t idPC;
  13.  
  14. idPA = getppid();
  15.  
  16. printf("\nProcesso A começou a executar...\n\n");
  17. printf("\nOla sou o Processo A\n\tA_PID:%5d\tA_PPID:%5d\n", getpid(), idPA);
  18.  
  19. idPA = fork();
  20.  
  21. if(idPA == 0){
  22. printf("\nProcesso B começou a executar...\n\n");
  23. printf("\nOla sou Processo B\n\tB_PID:%5d\tB_PPID:%5d\n", getpid(), getppid());
  24. idPB=fork();
  25. if (idPB == 0){
  26. printf("\nProcesso B.1 começou a executar...\n\n");
  27. printf("\nOlá sou Processo B.1\n\tB.1_PID:%5d\tB.1_PPID:%5d\n", getpid(), getppid());
  28. }else{
  29. idPB=fork();
  30. if (idPB == 0){
  31. printf("\nProcesso B.2 começou a executar...\n\n");
  32. printf("\nOla sou Processo B.2\n\tB.2_PID:%5d\tB.1_PPID:%5d\n", getpid(), getppid());
  33. }
  34. }
  35. else{
  36. sleep(2);
  37. printf("\nProcesso A:%5d\n", getpid());
  38. idPC=fork();
  39. if (idPC == 0){
  40. printf("\n");
  41. }
  42. }
  43.  
  44. sleep(100);
  45.  
  46.  
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement