#include <stdio.h>
#include <unistd.h>
int main()
{
pid_t pid;
pid = fork();
printf("pid : %d\n", getpid());
if( pid == 0)
{
printf("child: pid : %d \n", getpid());
while(1);
}
else
{
printf("parent: pid : %d \n", getpid());
//while(1);
}
}
In the above code snippet inside if
statement if we put while(1)
, it doesn't remains blocked and when enter key is pressed program is exited, but in case of parent if we put while(1)
, parent remains blocked until we give ctrl+c. Please clarify this behaviour of child.