Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following UNIX C program (Program B) / THREADED PROGRAM //To compil

ID: 3888728 • Letter: C

Question

Consider the following UNIX C program (Program B) / THREADED PROGRAM //To compile: g-1pthread //To Run: /a.out #include #include #include #include #include #include #include (14) Consider the following UNIX C program (Program A) //PROCESS PROGRAM //To compile: gt+ //To Run: ./a.out #include #include #include #include void funetion (int value): int surn = 0 int main (void) 1 int status int pidwaitpid (fork), &status;, 0) if (pid >0) I parent int sum1= 0; void grandChild (void ptr)sum++; void *child ( void pt sum++ l else child function (fork )) pthread.t thread; pthread.create (&thread;, NULL, grandChild, (void)NULL) pthread.join (thread, NULL) sum) printf("Sum: return 0 %d ", int main (void) 1 void function (int pArg) int status if (pArg != 0) { // CHILD pthreadt thread pthread.create(&thread;, NULL, child, (void pthread.join (thread, NULL) printf("SUM : %dp", sum ) ; return 0 )NULL): waitpid (pArg, &status;, 0) sum++ (a) Give the output from the above program. (b) How may threads are created? (c) What is the reason for the difference in the sum variable between Program A (a) Give the output for the above code. (b) How many processes were created? and Program B?

Explanation / Answer

Program A:

(a) OUTPUT => Sum : 1

Sum : 1

Sum : 1

(b) 4 process were created in total

Program B:

(a) OUTPUT => Sum = 3

(b) 2 threads were created, child and grandChild

(c) The difference is process and thread. In process each process executes seperately, so Sum = 1 always. But, in threads they are interdependent and its value increases Sum = 3

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote