Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need some help with this question 1) Simulate Process Creation a. Write a C/C+

ID: 3875252 • Letter: I

Question

I need some help with this question

1) Simulate Process Creation a. Write a C/C++ program to create a child process.

Your program should have the following components:

• Display a message to indicate the start of the program

• Make a system call fork() to create a child process

• Use if...else if...else (or switch...case) to determine if the process is created successfully or failed. If successful, print the parent or child process and its ID (getpid() for child process, getppid() for parent) accordingly; if failed, display a message to indicate that it failed.

• Before return 0 in the main, display a message to inform that the program has ended.

2) Simulate Inter-process Communication

a. Write a C/C++ program to simulate the inter-process communication between a child process and a parent process. You need to modify the program you wrote in the procedure 1). In your program:

• First, use pipe() to generate a buffer. The pipe should return a status (int), which should be tested to see if it is successful. If not, print error message.

• Create a child process.

• If the process creation is successful, send a short message (a character string) from child process by using write() to the pipe. In the parent process, use read() to receive the string from the child.

Explanation / Answer

1)First programme

#include <unistd.h>

using namespace std;

int main()

{

int pid;

pid = fork();

  

if (pid==0) //fork return zero newly created child process

{

cout << " Parent Process id : "<< getpid() << endl;

cout << " Child Process with parent id : "

<< getppid() << endl;

exit(1);

}

if(pid==-1){ //fork return negative value when process creation is unsuccessful

printf("errror in process");

}

return 0;

}

For Second programme

#include <stdio.h>

#include <unistd.h>