Question: This program runs on a c++ compiler within a Linux software. Please complete this assignment Modify this code to see what happens with processes. Recompile

This program runs on a c++ compiler within a Linux software. Please complete this assignment

Modify this code to see what happens with processes. Recompile and run it several times. Try adding a function to the code and call the function from both the parent and child process.

Add a pointer to the code and see if anything unusual happens (It may, intermittently!)

#include

#include

#include

#include

using namespace std;

int iglobal =1;

main ()

{

int iExample =10;

string sLocation;

pid_t pID = fork(); //Create a child process

if(pID==0)

{

//Child process code sLocation =In Child Process;

iExample++; //Think about the scope of these variables

iglobal++;

}//if(pID==0)

else if (pID <0) //Fork failed!

{

cout<

exit(1);

}//else if (pID<0)

else

{

sLocation=In parent process;

}

cout<

cout<

cout<

}//end main()

When you modified the code and recompiled it, what did you find?

When you tried adding a function to the code and called the function from both the parent and child process, what happened?

Did anything unusual happen when you added a pointer to the code?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!