Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 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){//P1 lewy
  11. printf("P1 lewy PID: %d\n", getpid());
  12. if (fork()==0){//P11 lewy
  13. printf("P11 lewy PID: %d\n", getpid());
  14. if (fork()==0){ //P111 lewy
  15. printf("P111 lewy PID: %d", getpid());
  16. sleep (120);
  17. return 0;}
  18. if (fork()==0){ //P112 prawy
  19. printf("P112 prawy PID: %d", getpid());
  20.  
  21. sleep (120);
  22. return 0;}
  23. sleep (120);
  24. return 0;}
  25. if(fork()==0){//P12 prawy X
  26. printf("P12 prawy PID: %d\n", getpid());
  27. //exec
  28. if(fork()==0) {//P22 prawy
  29. printf("P22 lewy PID: %d\n", getpid());
  30. sleep (120);
  31. return 0;}
  32. execlp("pstree", "pstree", "-c", getpid(), (char *)NULL);
  33. sleep(120);
  34. return 0;}
  35. }
  36.  
  37. if (fork()==0){//P22 prawy
  38. printf("P22 prawy PID: %d\n", getpid());
  39. if(fork()==0){//P22 prawy
  40. printf("P22 prawy PID: %d\n", getpid());
  41. if(fork()==0){//P221 lewy
  42. printf("P221 lewy PID: %d\n", getpid());
  43. sleep (120);
  44. return 0;}
  45. if (fork()==0){//P222 prawy
  46. printf("P222 prawy PID: %d\n", getpid());
  47. sleep (120);
  48. return 0;}
  49. sleep (120);
  50. return 0;}
  51. sleep(120);
  52. return 0;}
  53.  
  54. return 0;
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement