There are two process, parent process and child process There are some data in parent process stdin. The content is:
the 1 line
the 2 line
the 3 line
the 4 line
The parent process code:
//parent
fgets(buffer, 1000, stdin);
printf("I have data:%s", buffer); //print "I have data:the 1 line"
if(!fork())
{
fgets(buffer, 1000, stdin);
printf("I have data:%s", buffer); //print "I have data:the 2 line"
execv("child", NULL);
}
else
{
exit(0);
}
The child process code:
//child
main()
{
fgets(buffer, 1000, stdin); //blocked if parent stdin content size<4096
printf("I have no data:%s", buffer);
}
why? Is it possible for child process to read the third line in the stdin?