简体   繁体   English

我的C ++程序无法打开命名管道

[英]My C++ program cannot open named pipe

I am trying to run C++ application that works perfectly on Mac OS under Ubuntu. 我正在尝试运行在Ubuntu下的Mac OS上完美运行的C ++应用程序。 The problem is due to failure in opening a named pipe. 问题是由于无法打开命名管道。

I used mkfifo as follows: 我按以下方式使用了mkfifo

  pipe_name_ = std::string("/tmp/myfifo");
  if (mkfifo(pipe_name_.c_str(), 0666) < 0) {
     error_print("Cannot create a named pipe\n");
     return -1;
  }

  if ((fd_ = open(pipe_name_.c_str(), O_RDONLY | O_CREAT, 0666)) < 0) {
     error_print("Cannot open file description named %s %s\n",
                 pipe_name_.c_str(), strerror(errno));
     return -1;
  }

However, this prints into screen the bellow message that is for open() : 但是,这会在屏幕上显示open()以下消息:

Cannot open file description named /tmp/myfifo Invalid argument

My permissions status is as bellow: 我的权限状态如下:

$ls -la /tmp/myfifo
prw-r----- 1 hamidb nonconf 0 Jun 20 13:35 /tmp/myfifo
$umask
0027

I am wondering why it was working fine on Mac OS and not on Linux. 我想知道为什么它在Mac OS而不是Linux上能正常工作。

I believe that you have the wrong flags for open as you are not creating the file. 我认为您没有open文件的错误标志,因为您没有创建文件。

It should be 它应该是

open(pipe_name_.c_str(), O_RDONLY)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM