QUIZ 5 - Process Management
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);
}
}