Question
2. Assuming that the actual process ids of the parent and child process are 2600 and 2650 respectively, what will be printed out at lines
2. Assuming that the actual process ids of the parent and child process are 2600 and 2650 respectively, what will be printed out at lines A, B, C, D, E, and F? Be sure to explain your answers, specifically addressing sharing or non-sharing of variables between parent and child processes. int main() { pid_t x, y; int value = 90; value += 30; /* fork a child process */ x = fork(); if (x < 0) { /* error occurred */ fprintf(stderr,Fork failed); return(1); } else if (x == 0) { /* child process */ y = getpid(); printf(child: x = %d,x); /* A */ printf(child: y = %d,y); /* B */ value += 20; printf(child: value = %d , value); /* C */ exit(0); } else { /* parent process */
y= getpid(); printf(parent: x = %d,x); /* D */ printf(parent: y = %d,y); /* E */ wait(NULL); printf(parent: value = %d , value); /* F */ } }
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