Advertisement
Guest User

Untitled

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