2011-04-29 80 views
0

我想打开一个我刚刚打开的命令之前创建的文件。但它挂在open()命令行。你有什么主意吗?Unix系统编程:文件打开错误

if(mkfifo("test", S_IRWXU | S_IRWXG | S_IRWXO)) 
{ 
    printf("File creation error.\n"); 
    return 0; 
} 

// Hangs below 
while (((test_fd = open("test", O_RDONLY)) == -1) && (errno == EINTR)); 

回答

2

从mkfifo的手册页:

Opening a FIFO for reading normally blocks until some other process opens the same FIFO for writing, and vice versa. 
See fifo(7) for nonblocking handling of FIFO special files. 
+0

非常感谢你。我刚刚用O_RDWR更改了O_RDONLY,现在它正在工作。 – 2011-04-29 16:56:08