我创建了一个先进先出,但我无法从中读取。有什么问题?这是代码和输出。如果我在没有 O_NONBLOCK 程序的情况下使用 O_RDONLY,请稍候。
pid_t p;
int fd;
char str[]="sample";
mkfifo("myfifo", S_IRUSR | S_IWUSR);
fd = open("myfifo", O_RDWR);
printf("write %d byte\n", write(fd, str, 5));
close(fd);
fd = open("myfifo", O_RDONLY | O_NONBLOCK);
printf("read %d byte\n",read(fd, str, 6));
close(fd);
unlink("myfifo");
输出:
write 5 byte
read 0 byte