当前位置: 技术问答>linux和unix
删除消息队列的进程需要什么权限
来源: 互联网 发布时间:2017-03-09
本文导语: 我创建了一个消息队列,然后把他的权限设为0000,但是进程还是有办法删除消息队列。请问能删除消息队列的进程究竟有什么特别的权限呢?代码如下: #include #include //#include"common.h" int main() { int msgid,ret; ...
我创建了一个消息队列,然后把他的权限设为0000,但是进程还是有办法删除消息队列。请问能删除消息队列的进程究竟有什么特别的权限呢?代码如下:
#include
#include
//#include"common.h"
int main()
{
int msgid,ret;
struct msqid_ds buf;
msgid = msgget(111,0666 | IPC_CREAT);
if(msgid >= 0)
{
printf("Created a message queue.n");
ret = msgctl(msgid,IPC_STAT,&buf);
if(ret == 0)
printf("Mode is %o.n",buf.msg_perm.mode);
buf.msg_perm.mode = 0000;
ret = msgctl(msgid,IPC_SET,&buf);
if(ret == 0)
printf("After changed mode is %o.n",buf.msg_perm.mode);
ret = msgctl(msgid,IPC_RMID,NULL);
if(ret == 0)
printf("Removed a message queue.n");
}
return 0;
}
|
IPC_RMID
Immediately remove the message queue and its associated data structure, awakening all waiting reader and writer
processes (with an error return and errno set to EIDRM). The calling process must have appropriate (probably,
root) privileges or its effective user-ID must be either that of the creator or owner of the message queue.
manpage里写的很清楚。 你创建的那么creator和owner都是你,当前进程有效用户ID也是你,那么就可以删除,与Perm无关,
Immediately remove the message queue and its associated data structure, awakening all waiting reader and writer
processes (with an error return and errno set to EIDRM). The calling process must have appropriate (probably,
root) privileges or its effective user-ID must be either that of the creator or owner of the message queue.
manpage里写的很清楚。 你创建的那么creator和owner都是你,当前进程有效用户ID也是你,那么就可以删除,与Perm无关,