Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions

Question

1.. What are the roles of signs, symbols, and artifacts?

Answered: 1 week ago

Question

=+How might these stem from country and regional cultures?

Answered: 1 week ago