Question

Consider the following program: 1int main) 2nt count1; 3 int pid 0,pid2-0 4if ((pid - fork))) count-count 2; printf(%d , co

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer A
*********
2 , 1 parent and 1 child

Answer B
*********
3224
with waitpid line

Answer C
********
3242

without waitpid

Thanks 3 prints before the line and 224 or 242 prints at the next prompt.

Add a comment
Know the answer?
Add Answer to:
Consider the following program: 1int main) 2nt count1; 3 int pid 0,pid2-0 4if ((pid - fork))) cou...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 2Processes. Use the following assumptions to answer the questions: » All processes run to completion and no system calls will fail printf ( is atomic and calls fflush (stdout) after printing argument...

    2Processes. Use the following assumptions to answer the questions: » All processes run to completion and no system calls will fail printf ( is atomic and calls fflush (stdout) after printing argument(s) but before returning 1 int main) ( int status, pid, pid2 pid -fork O if (pid0) printf ("A") else pid2 fork ) if (pid20) printf ("C"); waitpid (pid, &status, 0) printf("D") 4 10 12 13 return; ) else ( printf("B") 14 15 17 19 return 0; 20 [8...

  • 1. (20 pts.) Consider the following C program. Assume that all functions complete successfully. Complete the...

    1. (20 pts.) Consider the following C program. Assume that all functions complete successfully. Complete the Process Model, given that the process id's (pids) are as shown for each process created. Fill in the boxes for each variable, p1 and p2, showing how the values change in each process. Just cross out old values (don't erase). int main ) Process Model int p1 = o, p2-0; pl-fork ) if (pl !# 0) p2 fork ( ); if (plp2 0) printf...

  • Source code to modify: #include <stdio.h> #include <unistd.h> #include <sys/types.h> int main() { pid_t pid; /*fork...

    Source code to modify: #include <stdio.h> #include <unistd.h> #include <sys/types.h> int main() { pid_t pid; /*fork a child process*/ pid = fork(); if (pid<0){ /*error occured*/ fprintf(stderr,"Fork failed\n"); return 1; } else if (pid == 0) { /*child process */ printf("I am the child %d\n",pid); execlp("/bin/ls","ls",NULL); } else { /*parent process */ /*parent will wait for the child to complete*/ printf("I am the parent %d\n",pid); wait(NULL); printf("Child Complete\n"); } return 0; } 1. Write program codes for 3.21 a and...

  • With explanation Please. #include #include <sys/types.h> <unistd.h> int main void ) fork fork fork execip (...

    With explanation Please. #include #include <sys/types.h> <unistd.h> int main void ) fork fork fork execip ( "/bin/ls", return 0 /* Line A /* Line B/ /*Line C/ /. Line D ./ "ls", NULL); Answer the following: (a) Including the initial parent process, how many processes are created by the program? (b) Answer (a) assuming that lines C and D are interchanged in the program (c) Answer (a) assuming that lines B and D are interchanged (instead of C and D)...

  • Suppose that you have three programs that are suppose to print a house diagram in a...

    Suppose that you have three programs that are suppose to print a house diagram in a collaborative manner. (i) prog1.c #include <stdio.h>      /* Input/Output */ #include <stdlib.h>     /* General Utilities */ int main() {     printf(“                      ^^^^^^^^^^^^                       \n”);     printf(“           ^^^^^^^^^^^            ^^^^^^^^^^^            \n”);     printf(“^^^^^^^^^^^                                  ^^^^^^^^^^^ \n”);     printf(“     |                                            |      \n”);     printf(“     |                                            |      \n”);     exit(1); } (i) prog2.c #include <stdio.h>      /* Input/Output */ #include <stdlib.h>     /* General Utilities */ int main() {     printf(“     |                                             |    ...

  • Consider the following pseudo code. What are the possible outputs (.e., the complete output from each...

    Consider the following pseudo code. What are the possible outputs (.e., the complete output from each execution run of this program)? Explain in less than 50 words. Note: keep in mind that fork) may fail in that case no child process is created int main(int arge, char argvt int X- int CwO; re - fork(); 15 tre > 0) X=S; else x-rc +2: printf(" \n", x); return 0;

  • p1.c outputs _________ and p2.c outputs__________ p1.c: int total = 0; int main( ) { if...

    p1.c outputs _________ and p2.c outputs__________ p1.c: int total = 0; int main( ) { if (fork( ) == 0) { total +=4; exit (0); } wait( NULL); total += 3; printf( “%d\n”, total); } p2.c: int total = 0; void *thread_start(void *v) { total += 4; } int main ( ) { pthread_t tid; pthread_create(&tis, NULL, thread_start, NULL); pthread_join(tid, NULL); total += 3; printf(“%d\n”, total); }

  • Q1) Including the initial parent process, how many processes are created by the program shown in...

    Q1) Including the initial parent process, how many processes are created by the program shown in Figure 1? Give an explanation for your answer. You can include an output statement to test and run the program. A sample output statement could be: printf("Testing......"); #include <stdio.h> #include <unistd.h> int main() { /*fork a child process*/ fork(); /*fork another child process*/ fork(); /*fork another child process*/ fork(); return 0; } Figure 1a - How many processes are created? Another version, now displaying...

  • Figure 〈 1013 > int main pid t pidfork if (pid0) printt "In child process: x*d\n",-x)...

    Figure 〈 1013 > int main pid t pidfork if (pid0) printt "In child process: x*d\n",-x) exit (0) printf ("In parent process: x return 0 *d\n", ++x) Part A- The Output of fork Let's examine the behavior of fork0 through a simple example. Consider the program in Figure 1. Figure 1) This program will produce two lines of output when executed. What are the values of x in each of these lines? Separate your answers for the first and second...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT