#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
key_t key = IPC_PRIVATE;
int id;
int semflg = 384;
id = shmget( key, 8192, semflg );谁能告诉我384的值对semflg有什么影响?
发布于 2016-04-02 04:32:02
shmget的手册页上写道:
除了上述标志外,shmflg的最低有效的9位指定授予所有者、组和其他人的权限。这些位与open(2)的模式参数具有相同的格式和含义。
让我们来看看打开的手册页
The following symbolic constants are provided for mode:
- S_IRWXU 00700 user (file owner) has read, write, and execute permission
- S_IRUSR 00400 user has read permission
- S_IWUSR 00200 user has write permission
- S_IXUSR 00100 user has execute permission
- S_IRWXG 00070 group has read, write, and execute permission
- S_IRGRP 00040 group has read permission
- S_IWGRP 00020 group has write permission
- S_IXGRP 00010 group has execute permission
- S_IRWXO 00007 others have read, write, and execute permission
- S_IROTH 00004 others have read permission
- S_IWOTH 00002 others have write permission
- S_IXOTH 00001 others have execute permission整数值384被编码为二进制的110000000,其对应于标志600,即S_IRUSR|S_IWUSR
具有写入权限和读取权限
不管是谁写了这段代码,他节省了2分钟的时间,而浪费了包括我在内的许多其他人的时间。
祝贺你。:)
编辑:感谢@Fabio Turati指出了一个主要错误;)
https://stackoverflow.com/questions/36362276
复制相似问题