在已经存在fifo1234文件的情况西,但是open的fd是-1,write和read的返回值都是-1,请问下大佬是怎么回事,谢谢?
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <wait.h>
int main(){
int pid = fork();
if(pid > 0){
int fd = open("fifo1234", O_RDWR);
printf("%d\n", fd);
char x[100] = "hello world";
int wo = write(fd, x, sizeof(x));
printf("[%d]\n", wo);
close(fd);
}
if(pid == 0)
{
int fd = open("fifo1234", O_RDONLY);
char recv[100]={0};
int ro = read(fd, recv, sizeof(recv));
printf("[%d]\n",ro);
printf("%s", recv);
close(fd);
}
return 0;
}