Question: Consider the following C program: #include #include #include int main ( int argc, char ** argv) { int count; if ((argc != 2) || (sscanf(argv[1],%d,

Consider the following C program: #include  #include  #include   int main(int argc, char **argv) { int count; if ((argc != 2) || (sscanf(argv[1],"%d",&count) != 1)) { fprintf(stderr,"Usage: %s  ", argv[0]); exit(1); } pid_t pid1, pid2; while(count > 0) { pid1 = fork(); if (pid1> 0) { pid2 = fork(); if (pid2 < 0) { perror("fork"); exit(1); } count = count - 1; } else if (pid1 == 0) { count = count / 2; } else { perror("fork"); exit(1); } } exit(0); } 

1.) If the command-line argument passed to this program is 0, this program creates no child process. How many child processes does this program create is the command-line argument is 1?

2.) Let us now assume that the command-line argument is 2. Consider the most distant descendant of the initial process. Say whether it is a child, a grand-child, a great-grand-child, a great-great-grand-child, etc.

3.) Let T(n) be the number of processes this program creates when its input is n (the answer to Question #1 above is thus T(1)).

Write an recursive formula (i.e., an induction, a recurrence relation) that gives T(i) as a function of one or more values of T for smaller input (i.e., smaller i). Explain your reasoning.

Feel free to double-check your formula by actually running the program and possibly augmenting it so that it allows you to count processes in whichever way you want.

4.) Say the maximum number of processes that can be created on your machine is 1 million (you can find out the actual number of your machine with ulimit -u).

For what value of the command-line argument would the above program be sure to experience failed fork() calls?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!