【发布时间】:2024-01-12 02:31:01
【问题描述】:
我正在重定向子进程中标准输入和标准输出的文件描述符,如下所示。 现在我希望子进程等到输入描述符中的数据可用。目前,如果输入描述符中的数据不可用,则子进程会采用一些随机值(我猜是 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 称为“一些随机值”,尤其是当您将标准输入显式设置为空文件时。
标签: c file-descriptor child-process