我在子进程中重定向标准输入和标准输出的文件描述符,如下所示。现在我希望子进程等到输入描述符中的数据可用。目前,如果输入描述符中的数据不可用,则子进程会采用一些随机值(我猜是 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);
}