each new process has it's own copy , with value before fork in it. please refer
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
void forkexample()
{
int x = 1;
if (fork() == 0)
printf("Child has x = %d\n", ++x);
else
printf("Parent has x = %d\n", --x);
}
int main()
{
forkexample();
return 0;
}
output
Parent has x = 0
Child has x = 2
(or)
Child has x = 2
Parent has x = 0
hence in above example
I ran this program compiler 4 5 times. it gave 2 only