在我的代码中,我创建了一个名为"my_fifo"的FIFO,如果我以O_WRONLY | O_NONBLOCK
模式打开它,open()会返回-1和错误号"No such device or address"。另一方面,如果我以O_RDONLY | O_NONBLOCK
模式打开FIFO,则可以正常工作。这是为什么?我做错了什么吗?
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
char *fifoname = "my_fifo";
mkfifo(fifoname, 0666);
int fd;
if ((fd = open(fifoname, O_WRONLY | O_NONBLOCK)) == -1)
{
perror("open pipe");
exit(EXIT_FAILURE);
}
close(fd);
exit(EXIT_SUCCESS);
}