Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following code and answer the following questions Assume a process will be successfully created. What would be the value of x and y

Consider the following code and answer the following questions

Assume a process will be successfully created. What would be the value of x and y at (A) & (B) ? Justify your answer.

Can someone help me on this operating system problems ?

#include

int x, y ; /* a global variable */

int main() {

int pid;

pthread_t tid ;

pthread_attr_t attr ;

x = 16; y =16;

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);

printf("x is %d,y is %d ", x, y); /* (B) */

}

} /* end of main */

void *runner(void *param) {

y=y*2;

x=x-y; Pthread_exit(0) ;

}

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_2

Step: 3

blur-text-image_3

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

DNA Databases

Authors: Stefan Kiesbye

1st Edition

0737758910, 978-0737758917

More Books

Students also viewed these Databases questions

Question

what is wearable technology in board games

Answered: 1 week ago