#include <unistd.h>
#include <stdio.h>
int child;
pid_t pid;
int main(void)
{
int i ;
for(i=0;i<3;i++)
{
pid = fork();
child = getpid();
if( pid == 0) // child
printf("Child process %d\n", child);
}
return 0;
}
This is my code.Each time the for loop is executing it's creating with fork an child process and a parent process.I don't know what process is created(child or parent) but i ask what is the child process and print the id number of it.And after executing the code it's displaying like
Child process:2001
Child process:2002
Child process:2003
Child process:2004
Child process:2005
Child process:2006