Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started