Question: Consider the following C function: int count = 0 ; pid _ t pid; pid _ t mystery ( ) { for ( int i

Consider the following C function:
int count =0; pid_t pid;
pid_t mystery(){
for (int i =0; i <4; ++i){
count +=1;
pid = fork();
if (pid !=0){
return pid;
}
}
return 0;
}
Which of the following is true about the above function? Select all that apply.
after calling this function, it is possible for the process that calls this function to wait upon and output the exit statuses of all the processes it creates
the assembly code generated for count +=1 will internally dereference a pointer since the location where count is stored is different in different processes
assuming the compiler keeps i in a register, at some point while this function is running, there will be multiple copies of the value of i
if fork fails (such as due to the system being out of memory), the function will crash or hang rather than returning
sometimes when the function returns, the value of the stack pointer will be different than it was just before it was called

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!