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

Consider the following code and answer the following questions. #include int x,

ID: 3885867 • Letter: C

Question

Consider the following code and answer the following questions. #include int x, y: /* a global variable */ int main() { int pid: pthread_t tid: pthread_attr_t attr: x = 4: y = 8: pid = fork(): if (pid == 0) { pthread_attr_init(&attr;): pthread_creat(&tid;, &attr;, runner, NULL): pthrad_Join(tid, NULL): printf("x is %d, y is %d ", x y): /* (A) */ } else if (pid > 0) { wait(NULL): y = y/x: printf (x is %d, y is %d ", x(y): /* (B) */ } } /* end of main */ void *runner(void *param) { x = y/4: x = x*y: Pthread_exit(0): } Assume a process will be successfully created. What would be the value of x and y at (A) & (B)? Justify your answer.

Explanation / Answer

Answer :

x is 16, y is 8
x is 4, y is 2

At first, x=4 and y=8
then if statement gets executed and runner will gets executed
x = y/4 -> x=2
x = x*y -> x=2*8=16 => x=16 and y=8

Then at else statement y = y/4 which results to 2, so x=4 and y=2

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