0% found this document useful (0 votes)
51 views2 pages

QUIZ 5 - Process Management

This document contains 3 questions about process management in C programming. Question 1 asks to draw a binary tree and count the number of processes created by a given code snippet. Question 2 asks what values of the variable x would be displayed by the child and parent processes in a given code snippet. Question 3 asks to write a master-slave implementation that accepts 5 filenames as arguments, creates 5 child processes to run the wc command on each file, and display the output.

Uploaded by

Garv Jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views2 pages

QUIZ 5 - Process Management

This document contains 3 questions about process management in C programming. Question 1 asks to draw a binary tree and count the number of processes created by a given code snippet. Question 2 asks what values of the variable x would be displayed by the child and parent processes in a given code snippet. Question 3 asks to write a master-slave implementation that accepts 5 filenames as arguments, creates 5 child processes to run the wc command on each file, and display the output.

Uploaded by

Garv Jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

QUIZ 5 – Process Management

Q1. Draw a binary to show the number of processes created by following code. What is the count of
number of processes created?
int main(void)
{
fork() && fork();
fork();
}

Q2. Consider the following code. What will be the value of variable x displayed from child processes and
parent process assuming that child processes terminates successfully.
int main(void)
{
int x = 10, status, childpid;
int pid1 = fork();
if (pid1 != 0)
{
childpid = wait(&status);
x = x + WEXITSTATUS(status);
printf("%d",x);
}
else
{
int pid2 = fork();
if (pid2 != 0)
{
childpid = wait(&status);
x = x + WEXITSTATUS(status);
printf("%d",x);
exit(x);
}
else
x = x + 5;
printf("%d",x);
exit(x);

}
}

Q3. Write a master-slave implementation for the following situation.


1. Main program accepts 5 filenames of text files as command line argument.
2. You need to create 5 child processes and pass each of the 5 filenames as a command line
argument to each of the 5 child process. For example first child will get the filename 1, second
child will get filename 2 and so on.
3. Child process will execute wc command for the filename provided and display the output from
the wc command.

You might also like