Guest User

Untitled

a guest
Mar 18th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. #include <stdio.h>
  4. #include <spawn.h>
  5. #include <unistd.h>
  6. #include <sys/wait.h>
  7.  
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12.  
  13. cout<<"Begning of the program"<<endl;
  14. int counter=0;
  15. pid_t child1=fork();
  16.  
  17.  
  18.  
  19. if(child1==0)
  20. {
  21.  
  22. cout<<"Child1 Process"<<endl;
  23. cout<<"Process ID: "<<getpid()<<endl;
  24. cout<<"Parrent ID: "<<getppid()<<endl;
  25.  
  26.  
  27. }
  28. else if(child1>0)
  29. {
  30. pid_t child2=fork();
  31. if(child2>0)
  32. {
  33. cout<<"Parrent of Child1 and Child2"<<endl;
  34. cout<<"Process ID: "<<getpid()<<endl;
  35. cout<<"Parrent ID: "<<getppid()<<endl;
  36.  
  37. }
  38. else if(child2==0)
  39. {
  40. cout<<"Child2 Creadted"<<endl;
  41. cout<<"Process ID: "<<getpid()<<endl;
  42. cout<<"Parrent ID: "<<getppid()<<endl;
  43.  
  44. }
  45.  
  46. else
  47. {
  48. cout<<"Process Failed"<<endl;
  49. }
  50.  
  51. }
  52. else
  53. {
  54. cout<<"Process fail"<<endl;
  55.  
  56. }
  57.  
  58. cout<<"End "<<endl;
  59.  
  60. return 0;
  61.  
  62. }
  63.  
  64. Begning of the program
  65. Parrent Process
  66. Process ID: 23539
  67. Parrent ID: 23296
  68. End
  69. Child1 Process
  70. Process ID: 23540
  71. Parrent ID: 1303
  72. End
  73. Child2 Process
  74. Process ID: 23541
  75. Parrent ID: 1303
  76. End
  77. Child1 Process
  78. Process ID: 23542
  79. Parrent ID: 1303
  80. End
Add Comment
Please, Sign In to add comment