I have a problem with understanding this code in system programming using C in Unix.
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <errno.h>
#include <unistd.h>
int main()
{
pid_t pid;
pid=fork();
if( pid > 0)
{
/* parent */
for( int i=0; i<1000 ;i++)
{
printf("\t\t Parent %d \n",i);
}
}
else
{
/*child */
for(int i=0; i<1000 ;i++)
{
printf("Child %d \n",i);
}
}
return 0;
}
When I executed it, it started to print parent 1 until 60, which means the pid is >0 so why it doesn't print parent until 999?
It switches between child and parent.