linux下删除共享内存的权限问题

jokenit 2010-12-16 10:28:46
比如root用户用“shmget(key, sizeof(DOMAIN)*nNum, IPC_CREAT|IPC_EXCL|0666);”创建了一块共享内存,发现test用户对此内存可读、可写,不过test用户用“shmctl(id, IPC_RMID, &shm);”去删除这块共享内存会失败,提示“Operation not permitted”。请问如何能让test用户也能删除这块共享内存呢?
...全文
298 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
mymtom 2010-12-16
  • 打赏
  • 举报
回复
可以试试用root吧这片共享内存转让给test用户
也就是使用IPC_SET设置shm_perm.uid为test用户的uid.
因为IPC_RMID要求如下用户id等于shm_perm.uid或者shm_perm.cuid,或者用户为root, 而shm_perm.cuid是不能改的。

IPC_RMID
Removes the shared memory identifier specified by the SharedMemoryID parameter from the system and
erases the shared memory segment and data structure associated with it. This command is only executed by
a process that has an effective user ID equal either to that of superuser or to the value of the
shm_perm.uid or shm_perm.cuid field in the data structure identified by the SharedMemoryID parameter


IPC_SET

Sets the user and group IDs of the owner as well as the access permissions for the shared memory segment
identified by the SharedMemoryID parameter. This command sets the following fields:

shm_perm.uid /* owning user ID */
shm_perm.gid /* owning group ID */
shm_perm.mode /* permission bits only */
hl0702xin 2010-12-16
  • 打赏
  • 举报
回复
setuid(0)或者以root用户的权限去运行这个程序就可以了 向ubuntu下的话:sudu 就可以了
  • 打赏
  • 举报
回复
0666是否只有读写权限啊?改成0777??
jokenit 2010-12-16
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 binqray 的回复:]

0666是否只有读写权限啊?改成0777??
[/Quote]

0777也试过,没用的

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧