Question: Modify the createNewProcess() function in the file named Processes.cpp as follows: The child process must print the message I am a child process! The child
Modify the createNewProcess() function in the file named Processes.cpp as follows: The child process must print the message I am a child process! The child process must then return a string with the message I am bored of my parent, switching programs now The parent process must print the message I just became a parent! The parent process must then wait until the child process terminates, at which point it must return a string with the message My child process just terminated! and then terminate itself. Hint: search for wait for process in the System Calls section of the Linux manual.
string createNewProcess(void) { pid_t id = fork(); // DO NOT CHANGE THIS LINE OF CODE process_id = id; if(id == -1) { return "Error creating process"; } else if (id == 0) { // TODO: Add your code here
return ""; } else { // TODO: Add your code here return ""; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
