i was doing some tracing on this code and it ended with printing 4 statements, 2 for parent and 2 for child but I am wondering how the order will be ? I know it depends on the CPU and it might differ from one computer to another, but what will be the possible solutions ? Cuz I thought of 6 different orders of these statements may appear.
#include <stdio.h>
#include <sys/types.h> #include <unistd.h>
void forkExample()
{
int z = 8;
if (fork() == 0)
{
fork();
printf("Child with z = %d\n", ++z);
}
else
{
fork();
printf("Parent with z = %d\n", --z);
}
}
int main()
{
forkExample(); return 0;
}