167k views
1 vote
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 proce

1 Answer

2 votes

Answer:

This is written in C++

This program uses no comment; See explanation section for detailed explanation

#include <iostream>

using namespace std;

void fork (string PID)

{

cout<<"This is process "<<PID;

}

int main ()

{

string PID;

cout<<"Enter Process ID: ";

cin>>PID;

fork(PID);

}

Step-by-step explanation:

This line includes the header file

#include <iostream>

This line calla namespace std

using namespace std;

This line defines function fork()

void fork (string PID)

{

This line executes the necessary operation

cout<<"This is process "<<PID;

}

The main method starts here

int main ()

{

This line declares string PID as the process ID

string PID;

This line prompts the user for process ID

cout<<"Enter Process ID: ";

This line inputs PID from the user

cin>>PID;

This line calls the function fork()

fork(PID);

}

User SaviNuclear
by
5.9k points