小编Mar*_*jaS的帖子

命名管道 - write()和read()的问题

我在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)

c++ ipc process named-pipes

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

c++ ×1

ipc ×1

named-pipes ×1

process ×1