C++ Assignment Setup  Part 1: Working With Process IDs  Modify the getProcessID() function in the file named Processes.cpp The function must find and store the process's own process id The function must return the process id to the calling program. Note that the function currently returns a default value of -1. Hint: search for “process id” in the “System Calls” section of the Linux manual. Part 2: Working With Multiple Processes  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. IMPORTANT: Do NOT type the messages, copy-paste them from here. Your output must be exact. Part 3: Working With External Commands  Modify the replaceProcess() function in the file named Processes.cpp as follows: The parent process will use the fork() function to create a child process. This step has been done for you. The child process must then change its memory image to a different program by using the execvp system call (http://linux.die.net/man/3/execvp). The parameter args that has been passed to the replaceProcess() function is the array of parameters to be passed to execvp, telling it which program to execute and what parameters to pass to that program. For example, the test code provided to you executes the “ls” (directory list) program with the parameter “-al” by setting the args array as follows: char * args[3] = {(char * )"ls", (char * )"-al", NULL}; IMPORTANT: Although the test code executes the “ls” program, we must be able to change the command that execvp executes. So, DO NOT hardcode the command to be passed to execvp. Simply use the args array provided. Finally, in the parent process, you must make sure to invoke the necessary system call to wait for the child process to terminate. Once the child terminates, exit the program.     Expected Output: If you execute the code you pull from GitLab without any modifications, it will produce the following output:       If you make all required changes correctly, your program should produce output similar to the following:   below is my code which isnt giving the correct output when i run it // // Processes.cpp // ITSC 3146 // // Created by Bahamon, Julio on 1/12/17. // /* @file Processes.cpp @author student name, student@uncc.edu @author student name, student@uncc.edu @author student name, student@uncc.edu @description: @course: ITSC 3146 @assignment: in-class activity [n] */ #ifndef Processes_cpp #define Processes_cpp //Import required header file #include "Processes.h" using namespace std; //Part 1: Working With Process IDs pid_t getProcessID(void) {       // TODO: Add your code here       //Get the pid of the process       pid_t id = getpid();       //return the id       return id; } //Part 2: Working With Multiple Processes //Implement method to create child process string createNewProcess(void) {       //Create a child process       pid_t id = fork();       // DO NOT CHANGE THIS LINE OF CODE       process_id = id;       //If the id is -1       if (id == -1)       {             return "Error creating process";       }       //If the ID is 0       else if (id == 0)       {             cout << "I am a child process! ";             return "I am bored of my parent, switching programs now";       }       //Otherwise       else       {             cout << "I just became a parent! ";             int status = 0;             wait(&status);             return "My child process just terminated!";       } } //Part 3: Working With External Commands" //Implement the method to replace the process void replaceProcess(char * args[]) {       //Create child process       pid_t id = fork();       //Execute with the new process       execvp(args[0], args); } #endif /* TestProg_cpp */ the output is in images

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

C++

Assignment Setup 

Part 1: Working With Process IDs 

  1. Modify the getProcessID() function in the file named Processes.cpp

    1. The function must find and store the process's own process id

    2. The function must return the process id to the calling programNote that the function currently returns a default value of -1.
      Hint: search for “process id” in the “System Calls” section of the Linux manual.

Part 2: Working With Multiple Processes 

  1. Modify the createNewProcess() function in the file named Processes.cpp as follows:

    1. The child process must print the message I am a child process!

    2. The child process must then return a string with the message I am bored of my parent, switching programs now

    3. The parent process must print the message I just became a parent!

    4. 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.

      IMPORTANT:
      Do NOT type the messages, copy-paste them from here. Your output must be exact.

Part 3: Working With External Commands 

  1. Modify the replaceProcess() function in the file named Processes.cpp as follows:

    1. The parent process will use the fork() function to create a child process. This step has been done for you.

    2. The child process must then change its memory image to a different program by using the execvp system call (http://linux.die.net/man/3/execvp). The parameter args that has been passed to the replaceProcess() function is the array of parameters to be passed to execvp, telling it which program to execute and what parameters to pass to that program.

For example, the test code provided to you executes the “ls” (directory list) program with the parameter “-al” by setting the args array as follows:

char * args[3] = {(char * )"ls", (char * )"-al", NULL};

IMPORTANT:
Although the test code executes the “ls” program, we must be able to change the command that execvp executes. So, DO NOT hardcode the command to be passed to execvp. Simply use the args array provided.

  1. Finally, in the parent process, you must make sure to invoke the necessary system call to wait for the child process to terminate. Once the child terminates, exit the program.

 

 

Expected Output:

If you execute the code you pull from GitLab without any modifications, it will produce the following output:

 

    If you make all required changes correctly, your program should produce output similar to the following:

 

below is my code which isnt giving the correct output when i run it

//
// Processes.cpp
// ITSC 3146
//
// Created by Bahamon, Julio on 1/12/17.
//


/*
@file Processes.cpp
@author student name, student@uncc.edu
@author student name, student@uncc.edu
@author student name, student@uncc.edu
@description: <ADD DESCRIPTION>
@course: ITSC 3146
@assignment: in-class activity [n]
*/

#ifndef Processes_cpp

#define Processes_cpp

//Import required header file

#include "Processes.h"

using namespace std;

//Part 1: Working With Process IDs

pid_t getProcessID(void)

{

      // TODO: Add your code here

      //Get the pid of the process

      pid_t id = getpid();

      //return the id

      return id;

}

//Part 2: Working With Multiple Processes

//Implement method to create child process

string createNewProcess(void)

{

      //Create a child process

      pid_t id = fork();

      // DO NOT CHANGE THIS LINE OF CODE

      process_id = id;

      //If the id is -1

      if (id == -1)

      {

            return "Error creating process";

      }

      //If the ID is 0

      else if (id == 0)

      {

            cout << "I am a child process! ";

            return "I am bored of my parent, switching programs now";

      }

      //Otherwise

      else

      {

            cout << "I just became a parent! ";

            int status = 0;

            wait(&status);

            return "My child process just terminated!";

      }

}

//Part 3: Working With External Commands"

//Implement the method to replace the process

void replaceProcess(char * args[])

{

      //Create child process

      pid_t id = fork();

      //Execute with the new process

      execvp(args[0], args);

}

#endif /* TestProg_cpp */

the output is in images

Part 1: Working With Process IDs
Process ID: 3329
Part 2: Working With Multiple Processes
I just became a parent!
I am a child process!
I am bored of my parent, switching programs now
My child process just terminated!
Part 3: Working With External Commands
total 52
-rwxr-xr-x 1 ubuntu ubuntu 14570 Jan 20 20:21 Assignment_3_2
-rw-r--r-- 1 ubuntu ubuntu
-rw-r--r-- 1 ubuntu ubuntu 4984 Jan 20 20:21 Assignment_3_2.0
-rw-r--r-- 1 ubuntu ubuntu
-rw-r--r-- 1 ubuntu ubuntu 1466 Jan 20 20:20 Processes.cpp
1124 Jan 20 20:18 Assignment_3_2.cpp
378 Jan 20 20:18 Makefile
-rw-r--r-- 1 ubuntu ubuntu
-rw-r--r-- 1 ubuntu ubuntu
-rw-r--r-- 1 ubuntu ubuntu
495 Jan 20 20:18 Processes.h
5088 Jan 20 20:21 Processes.o
905 Jan 20 20:18 Processes_SK.cpp
Transcribed Image Text:Part 1: Working With Process IDs Process ID: 3329 Part 2: Working With Multiple Processes I just became a parent! I am a child process! I am bored of my parent, switching programs now My child process just terminated! Part 3: Working With External Commands total 52 -rwxr-xr-x 1 ubuntu ubuntu 14570 Jan 20 20:21 Assignment_3_2 -rw-r--r-- 1 ubuntu ubuntu -rw-r--r-- 1 ubuntu ubuntu 4984 Jan 20 20:21 Assignment_3_2.0 -rw-r--r-- 1 ubuntu ubuntu -rw-r--r-- 1 ubuntu ubuntu 1466 Jan 20 20:20 Processes.cpp 1124 Jan 20 20:18 Assignment_3_2.cpp 378 Jan 20 20:18 Makefile -rw-r--r-- 1 ubuntu ubuntu -rw-r--r-- 1 ubuntu ubuntu -rw-r--r-- 1 ubuntu ubuntu 495 Jan 20 20:18 Processes.h 5088 Jan 20 20:21 Processes.o 905 Jan 20 20:18 Processes_SK.cpp
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 7 steps with 3 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY