1
我正在將stdin和stdout的文件描述符重定向到子進程中,如下所示。 現在我想讓子進程等待,直到輸入描述符中的數據可用。目前,如果數據在輸入描述符處不可用,那麼子進程需要一些隨機值(我猜EOF)並終止。等待來自文件描述符的輸入
fd0=open("in1.dat", O_RDWR|O_CREAT);
fd1=open("out1.dat", O_RDWR|O_CREAT);
if(pid==0)
{
dup2(fd0, 0); // redirect input to the file
dup2(fd1, 1); // redirect output to the file
execlp("./flip","flip","new","4",NULL);
}
我幾乎不會調用EOF「一些隨機值」,尤其是當您將stdin明確設置爲空文件時。 – 2011-05-10 02:52:52