Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C program that uses the fork() system call to create a total of 9 processes (including the parent process). Your program must print

Write a C program that uses the fork() system call to create a total of 9 processes (including the parent process). Your program must print the pids of all the processes created to a file.

  • To get the pid of the current process use the getpid() function.
  • I posted a couple of examples on the lab 4 section. Please study these files.
  • If you wish you can modify one of example files to create 9 processes.

/**

* You can verify your answer by counting

* the number of unique processes which are output

* by the call to getpid() - which is 3 unique processes.

* Note: The statement 'printf("%d ",getpid());' prints

* the pid of the current process.

* Process tree: The root P1 has two children P2 and P3.

*/

#include

#include /* This header file has the definition for pid_t

type*/

int main()

{

pid_t pid;

printf("%d ",getpid()); /*This Will print the root*/

pid = fork();

printf("%d ",getpid());

if(pid == 0) {

/*Do Nothing*/

}

else {

fork();

printf("%d ",getpid());

}

return 0;

}

  • There are two deliverables for this lab:
    • The C code for lab 4.
    • Print the output in a text file named output.txt or take a screenshot for the result.

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

SQL Server Query Performance Tuning

Authors: Sajal Dam, Grant Fritchey

4th Edition

1430267429, 9781430267423

More Books

Students also viewed these Databases questions