【发布时间】:2014-07-28 18:40:42
【问题描述】:
这是我的简单代码,它打开一个命名管道,向它写入一个字符串,然后关闭管道。管道是在另一个函数中创建的,如下所述。
char * ipcnm = "./jobqueue";
std::cout << "opening job queue" << std::endl;
//ensure the jobqueue is opened
if ((jobq = open(ipcnm, O_WRONLY)) < 0) {
perror("open");
exit(-1);
}
std::cout << "queue opened" << std::endl;
// record the number of bytes written to the queue
size_t written = write(jobq, ptr, size*nmemb);
// close fifo
if (close(jobq) < 0) {
perror("close");
exit(-1);
}
// need to report to other agents the size of the job that was written
jobSizes.push_back(written);
但是对 open() 的调用挂起。我确保在调用时没有其他进程使用fifo“jobqueue”,并且队列创建后的文件权限设置为prwxrwxr-x(我只是使用mkfifo(ipcnm, 0777)创建管道.
起初我认为这是一个问题,该组 o 缺少此管道上的 w 权限,所以我使用 chmod 手动更改了它们,但它仍然挂起,因为“队列打开”从未被打印出来。 perror("open"); 的错误消息也没有。
我错过了什么?
【问题讨论】:
标签: c++ linux ipc named-pipes mkfifo