Question: 3. (20 points) In the following two programs, the executable program /bin/prog does not print anything, and printf() always prints immediately i.e., there is no

 3. (20 points) In the following two programs, the executable program

3. (20 points) In the following two programs, the executable program "/bin/prog" does not print anything, and printf() always prints immediately i.e., there is no I/O buffering). int main(int arge, char +argv[]) { // prog-1 int rc = fork(); if (rc == 0) { printf("1"); } else if (rc > 0) { wait (NULL); printf("2"); } else { printf("3"); return 0; (1) If the calls to fork () and wait() always succeed, list all the possible outputs of the above program i.e., prog-1). (2) If the calls to fork () and wait () might fail, list all the possible outputs of the above program (i.e., prog-1) and explain how each of the outputs may happen. int main(int argc, char *argv[]) { // prog-2 int rc = fork(); if (rc == 0) { char *argv[] = { "/bin/prog", NULL); execv(argv[0], argv); printf("1"); } else if (rc > 0) { printf("2"); printf("3"); return 0; (3) If the calls to fork () and execv() always succeed, list all the possible outputs of the above program i.e., prog-2). (4) If the calls to fork () and execv() might succeed, list all the possible outputs of the above program i.e., prog-2) and explain how each of the outputs may happen. 3. (20 points) In the following two programs, the executable program "/bin/prog" does not print anything, and printf() always prints immediately i.e., there is no I/O buffering). int main(int arge, char +argv[]) { // prog-1 int rc = fork(); if (rc == 0) { printf("1"); } else if (rc > 0) { wait (NULL); printf("2"); } else { printf("3"); return 0; (1) If the calls to fork () and wait() always succeed, list all the possible outputs of the above program i.e., prog-1). (2) If the calls to fork () and wait () might fail, list all the possible outputs of the above program (i.e., prog-1) and explain how each of the outputs may happen. int main(int argc, char *argv[]) { // prog-2 int rc = fork(); if (rc == 0) { char *argv[] = { "/bin/prog", NULL); execv(argv[0], argv); printf("1"); } else if (rc > 0) { printf("2"); printf("3"); return 0; (3) If the calls to fork () and execv() always succeed, list all the possible outputs of the above program i.e., prog-2). (4) If the calls to fork () and execv() might succeed, list all the possible outputs of the above program i.e., prog-2) and explain how each of the outputs may happen

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!