#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
int x=10, y=20, z=30;
printf("Message 0 : x=%d, y = %d, z = %d\n", x,y,z);
x=fork();
y=fork();
if (x != 0) printf("Message 1 : x=%d, y = %d, z = %d\n", x,y,z);
if (y != 0) printf("Message 2 : x=%d, y = %d, z = %d\n", x,y,z);
z=fork();
if ((x>0) || (y>0) || (z>0)) printf ("Message 3 : x=%d, y=%d, z= %d\n", x,y,z);
if ((x==0) && (y==0) && (z!=0)) printf ("Message 4 : x=%d, y = %d, z=%d\n",x,y,z);
if ((x!=0) && (y!=0) && (z!=0)) printf ("Message 5 : x=%d, y=%d, z=%d\n",x,y,z);
}
Above is a code that I compiled in Unix. The picture I attached is how I see the forks creating the processes.
My question is how do I decide which is a parent process and which is a child process? If there is anything wrong with my picture do tell me too.