int main(){
mkfifo("view",0666);
int pid = fork();
if(pid==0){
close(1);
int fd = open("view",O_WRONLY);
dup(fd);
execlp("cat", "cat", "users", NULL);
close(fd);
}
else{
wait(NULL);
int fd = open("view",O_RDONLY);
char resp[100];
read(fd,resp,20);
printf("%s\n",resp);
close(fd);
}
}
我有這段代碼,但由於某種原因,當我執行它時,procces死機,沒有打印,沒有退出(我必須按CTRL + C)。 任何想法爲什麼?我嘗試了同樣的事情,但使用內部管道,它工作。Combine fork,fifo和execlp?