Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 "/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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started