Share
Explore BrainMass

Forking and Scheduling: Few programs and problems

[A] What happens when you run the following piece of code:

main(int argc, char ** argv)
{
for(;;)
fork();
}

[B] Given the following piece of code:

main(int argc, char ** argv)
{
int child = fork();
int c = 5;

if(child == 0)
{
c += 5;
}
else
{
child = fork();
c += 10;
if(child)
c += 5;
}
}

How many different copies of the variable c are there? What are their values?

[C] Given the following piece of code

main(int argc, char ** argv)
{
forkthem(5)
}

void forkthem(int n)
{
if(n > 0)
{
fork();
forkthem(n-1);
}
}

How many processes are created if the above piece of code is run?

[D] Most round-robin schedulers use a fixed size quantum. Give an argument in favor of and against a small quantum.

Attachments

Solution Preview

[A] This program creates a "fork bomb" that will keep on creating copies of itself forever. Very soon, the limit on maximum number of user processes for the user is reached (please refer to "ulimit -a" output for this limit) and no further process can be created by the user. Further "fork" attempts will give the error ...

Solution Summary

Solution explains the concept of "fork bomb" and effects of "smaller quantum" in fixed-size quantum round-robin scheduling, apart from giving detailed explanations behind the solution in not-so-obvious cases.

$2.19