Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- #include <stdio.h>
- #include <spawn.h>
- #include <unistd.h>
- #include <sys/wait.h>
- using namespace std;
- int main()
- {
- cout<<"Begning of the program"<<endl;
- int counter=0;
- pid_t child1=fork();
- if(child1==0)
- {
- cout<<"Child1 Process"<<endl;
- cout<<"Process ID: "<<getpid()<<endl;
- cout<<"Parrent ID: "<<getppid()<<endl;
- }
- else if(child1>0)
- {
- pid_t child2=fork();
- if(child2>0)
- {
- cout<<"Parrent of Child1 and Child2"<<endl;
- cout<<"Process ID: "<<getpid()<<endl;
- cout<<"Parrent ID: "<<getppid()<<endl;
- }
- else if(child2==0)
- {
- cout<<"Child2 Creadted"<<endl;
- cout<<"Process ID: "<<getpid()<<endl;
- cout<<"Parrent ID: "<<getppid()<<endl;
- }
- else
- {
- cout<<"Process Failed"<<endl;
- }
- }
- else
- {
- cout<<"Process fail"<<endl;
- }
- cout<<"End "<<endl;
- return 0;
- }
- Begning of the program
- Parrent Process
- Process ID: 23539
- Parrent ID: 23296
- End
- Child1 Process
- Process ID: 23540
- Parrent ID: 1303
- End
- Child2 Process
- Process ID: 23541
- Parrent ID: 1303
- End
- Child1 Process
- Process ID: 23542
- Parrent ID: 1303
- End
Add Comment
Please, Sign In to add comment