Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For the following C++ Code: #include #include #include #include #include #include #include #include #include #include #include Processes.h using namespace std; pid_t process_id; /* * The

For the following C++ Code:

#include #include #include #include #include #include #include #include #include #include #include "Processes.h"

using namespace std;

pid_t process_id;

/* * The starting point of the program. */ int main(void) { // Call the user-defined function that retrieves the process ID cout

// Call the function that call an external OS command if (process_id != 0) { cout

return 0; }

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Use the following C++ code to complete:

#ifndef Processes_cpp #define Processes_cpp

#include "Processes.h"

using namespace std;

// Part 1: Working With Process IDs pid_t getProcessID(void) { // TODO: Add your code here return -1; }

// Part 2: Working With Multiple Processes 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 ""; } }

// Part 3: Working With External Commands" void replaceProcess(char * args[]) { // Spawn a process to execute the user's command. pid_t id = fork(); // TODO: Add your code here }

#endif /* TestProg_cpp */

image text in transcribed

Correct code output:

image text in transcribed

1. Modify the getProcessID() function in the file named Processes.cpp a. The function must find and store the process's own process id b. The function must return the process id to the calling program. Hint: search for "process id" in the "System Calls" section of the Linux manual

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Power Of Numbers In Health Care A Students Journey In Data Analysis

Authors: Kaiden

1st Edition

8119747887, 978-8119747887

More Books

Students also viewed these Databases questions

Question

What do you mean by exceptions ?

Answered: 1 week ago