Question: Write a simple C or C++ program to call fork() and print a message with its PID (e.g., This is process PID) where PID is

Write a simple C or C++ program to call fork() and print a message with its PID (e.g., "This is process PID") where PID is the process ID of the process. You may write one program to do all cases (or a separate program to do each case).

Case1. fork(); // followed by a print statement

Case2. fork(); fork(); // followed by a print statement

Case3. fork(); fork(); fork(); // followed by a print statement

Case4.

if (pid=fork() && pid2 = fork()) {fork();}

if (pid=fork() && pid2 = fork()) {fork();}

if (pid=fork() && pid2 = fork()) {fork();}

Case5.

// followed by a print statementCase 5.

for (int i=1; i<=5; i++) {fork();}

// followed by a print statement

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!