0

While using the FIFO to transmit information between different processes, I found out that the file that the mkfifo create cannot be accessed by the processes. I do not know how to change my program. Please help :(

    if (mkfifo("signal", O_CREAT) < 0)
    {
        cerr << "Errors occur :(" << endl;
        cerr << errno << endl;
        exit(1);
    }

And the authority of the file named signal is like the following:

    p---rwx---
4

1 回答 1

0

如果您阅读手册页,您会知道这O_CREAT是一个无效参数mkfifo()

mkfifo() 创建一个名为 pathname 的 FIFO 特殊文件。mode 指定 FIFO 的权限。它由进程的umask以通常的方式修改:创建文件的权限为(mode & ~umask)。

权限位标志在您的系统中定义,<sys/stat.h>可以通过阅读stat(2). 以下是相关列表:

S_IRUSR    00400     owner has read permission
S_IWUSR    00200     owner has write permission
S_IXUSR    00100     owner has execute permission

S_IRGRP    00040     group has read permission
S_IWGRP    00020     group has write permission
S_IXGRP    00010     group has execute permission

S_IROTH    00004     others have read permission
S_IWOTH    00002     others have write permission
S_IXOTH    00001     others have execute permission

因此,通过将正确的权限标志传递给mkfifo(). 说你想要rw-rw-rw,然后你会这样做:

mkfifo("signal", S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
于 2015-06-08T13:35:31.767 回答