2015-06-08 91 views
0

雖然使用FIFO在不同進程間傳輸信息,但我發現進程無法訪問mkfifo創建的文件。我不知道如何改變我的程序。請幫助:(沒有權限訪問由mkfifo創建的文件

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

和文件名爲信號的權限如下所示:

p---rwx--- 

回答

0

如果你讀手冊頁,你就會知道O_CREAT是一個無效的參數mkfifo()

mkfifo()生成一個名爲pathname的FIFO特殊文件mode指定FIFO的權限,它由進程的umask以通常的方式修改:創建的文件是(模式&〜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); 
相關問題