有两个进程,父进程和子进程父进程stdin中有一些数据。内容是:
the 1 line
the 2 line
the 3 line
the 4 line
父进程代码:
//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);
}
子进程代码:
//child
main()
{
fgets(buffer, 1000, stdin); //blocked if parent stdin content size<4096
printf("I have no data:%s", buffer);
}
为什么?子进程是否可以读取标准输入中的第三行?