親プロセスと子プロセスの 2 つのプロセスがあります。親プロセス 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);
}
なぜ?子プロセスが stdin の 3 行目を読み取ることは可能ですか?