Hi,
Can someone please help me with this question, I know its pretty basic but i just cant seem to get my head around it???
THE CODE:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int varA = 40;
int main(int argc, int **argv)
{
int varB = 29;
pid_t retFork=2;
fprintf(stderr, "PID: %4ld retFork:%2d varA: %2d varB: %2d\n", getpid(), retFork, varA, varB);
retFork = fork();
varA = 80;
fprintf(stderr, "PID: %4ld retFork:%2d varA: %2d varB: %2d\n", getpid(), retFork, varA, varB);
switch (retFork){
case -1:
fprintf(stderr, "The fork system call failed\n" );
fprintf(stderr, "PID: %4ld retFork: %2d\n", getpid(), retFork);
exit(1);
case 0:
varA += 10;
varB += 10;
fprintf(stderr, "PID: %4ld retFork: %2d\n", getpid(), retFork);
break;
default:
fprintf(stderr, "PID: %4ld retFork: %2d\n", getpid(), retFork);
varA += 25;
varB += 25;
exit(1);
}
sleep (2.0);
fprintf(stderr, "PID: %4ld varA: %2d varB: %2d\n", getpid(), varA, varB);
return 0;
}
THE OUTPUT:
PID: 32613 retFork: 2 varA: 40 varB: 29
PID: 32614 retFork: 0 varA: 80 varB: 29
PID: 32614 retFork: 0
PID: 32614 varA: 90 varB: 39
PID: 32613 retFork:32614 varA: 80 varB: 29
PID: 32613 retFork: 32614
THE QUESTION:
ii. Observe that the values of the three variables retFork, varA and varB change. Explain the reason for the change to the values of variables retFork, varA and varB.
plzzzz can someone help??
thanks