2011-04-29 57 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