#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
//fork();
//printf("Hello World\n");
int i=fork();
// child process because return value zero
if (i == 0)
printf("Hello from Child! %d \n",i);
// parent process because return value non-zero.
if (i!=0)
printf("Hello from Parent! %d \n",i);
return 0;
}
Why the first output is giving two print output while other are only giving outputs from the Parent Only - when fork() creates two processes.
I am expecting two output print in each output case because of the existence of two process.
Can anyone explain why ?
Output 1:
Hello from Parent! 600
Hello from Child! 0
Output 2:
Hello from Parent! 8206
Output 3:
Hello from Parent! 350
Output 4:
Hello from Parent! 1098
Why the first output is giving two print output while other are only giving single outputs from the Parent Only - when fork() creates two processes. I am expecting two output print in output case.