Question: C++ operating system What does the following program output? What does it imply about global variables and the fork() command? How does the output change
C++ operating system
What does the following program output? What does it imply about global variables and the fork() command? How does the output change if int nums[SIZE] is moved into main()? (15 pts)
int nums[SIZE] = {0,1,2,3,4};
int main(){
pid_t pid;
pid = fork();
if (pid == 0){
for (int i = 0; i < SIZE; i++){
nums[i] *= -i;
printf("CHILD: %d ",nums[i]);
}
printf(" ");
}else if (pid > 0){
wait(NULL);
for (int i = 0; i < SIZE; i++)
printf("PARENT: %d ",nums[i]);
printf(" ");
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
