我在LINUX下用C++编程.我有两个独立的过程.我应该使用命名管道提供通信.
读者: - 使用mkfifo创建FIFO - status = mkfifo(myFIFO,0666) - 使用open打开管道 - fifo = open(myFIFO,O_RDONLY) - 从管道读取 - num = read(fifo,temp,sizeof(temp))
作家:-opens pipe - fifo = open(myFIFO,O_WRONLY); -writes to pipe - num = write(fifo,string,strlen(string));
我注意到为读进程和写进程返回的文件描述符是0.此外,在命令写入后,我可以在我的终端上看到应该写入管道的字符串.我不知道为什么它会在终端上显示...而且,写入的字节数是0 ......
你能帮帮我吗?谢谢!!!
// read.cpp:
#define myFIFO "/temp/FIFO"
int main(){
int num, fifo, status;
char temp[32];
if (status = mkfifo(myFIFO, 0666) < 0) {
printf("\n %s \n", strerror(errno));
return 0;
}
if (fifo = open(myFIFO, O_RDONLY) < 0) {
printf("\n %s \n", strerror(errno));
return 0;
}
if …Run Code Online (Sandbox Code Playgroud)