Question: this is my current code : #include #include #include #include #include #include using namespace std; int main ( ) { pid _ t pid; /
this is my current code : #include
#include
#include
#include
#include
#include
using namespace std;
int main
pidt pid; process id
const char message;
int n;
int exitcode;
cout "fork program starting
;
pid fork;
switch pid
case :
cout "Fork failure!
;
return ;
case :
message "This is the child
;
n ;
exitcode ;
Create grandchi ld
pidt grandchildpid fork;
if grandchildpid
Grandchild process
cout "Grandchild Process. ID: getpid Parent ID: getppid Grandparent ID: getppid endl;
exit; Grandchild exits
else
Child waits for grandchild to finish
int grandchildstatus;
wait&grandchildstatus;
cout "Grandchild finished, ID: grandchildpid endl;
break;
default:
message "This is the parent
;
n ;
exitcode ;
break;
for int i ; i n; i
cout message;
sleep;
Waiting for child to finish
if pid parent
int statval;
pidt childpid;
childpid wait&statval; wait for child
cout "Child finished: PID childpid endl;
if WIFEXITEDstatval
cout "child exited with code WEXITSTATUSstatval endl;
else
cout "child terminated abnormally!" endl;
exitexitcode;
i need help adding this to it as i tried it is only running the pid of thr child and exit : Modify the program so that the child process creates another child and waits for it The grandchild prints
out the IDs of itself, its parent and grandparent.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
