Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <unistd.h>
  4.  
  5. int main(void){
  6. char pid[10];
  7. sprintf(pid, "%d", getpid());
  8. printf("Macierzysty PID: %d\n", getpid());
  9.  
  10. if(fork()==0){//P22 prawo od macierzystego
  11. printf("7.prawo PID: %d\n", getpid());
  12. if(fork()==0){//P23 prawo
  13. printf("8.prawo PID: %d\n", getpid());
  14. if(fork()==0){//P24 lewo
  15. printf("9.prawo PID: %d\n", getpid());
  16. sleep (2);
  17. return 0;
  18. }
  19. if(fork()==0){//P25 prawo
  20. printf("10.prawo PID: %d\n", getpid());
  21. sleep(2);
  22. return 0;
  23. }
  24. sleep(2);
  25. return 0;
  26. }
  27. sleep(2);
  28. return 0;
  29. }
  30.  
  31. if (fork()==0){//P1 lewy
  32. printf("1.Lewo PID: %d\n", getpid());
  33. if (fork()==0){//P2 prawy X
  34. printf("5.prawo PID: %d\n", getpid());
  35. if (fork()==0){//P3 prawy
  36. printf("6.prawo PID: %d\n", getpid());
  37. sleep (2);
  38. return 0;
  39. }
  40. execlp("pstree", "pstree", "-c", pid, (char *)NULL); //pstrees
  41. sleep(2);
  42. return 0;
  43. }
  44. if(fork()==0){//P2 lewy
  45. printf("2.Lewo PID: %d\n", getpid());
  46. if(fork()==0){//P3 lewy
  47. printf("3.Lewo PID: %d\n", getpid());
  48. sleep(2);
  49. return 0;
  50. }
  51. if(fork()==0){//P3 prawy
  52. printf("4.prawo PID: %d\n", getpid());
  53. sleep(2);
  54. return 0;
  55. }
  56. sleep(2);
  57. return 0;
  58. }
  59.  
  60.  
  61. sleep (2);
  62. return 0;
  63.  
  64. }
  65.  
  66.  
  67.  
  68.  
  69. sleep(2);
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement