C 队列创建权限被拒绝
我正在尝试创建队列,但收到权限被拒绝错误。我之前遇到过这个错误,但后来我添加了用于捕获密钥创建错误的代码,并且它正在工作。从那时起我唯一改变的是我将队列创建代码放在一个单独的函数中。这是我的代码的样子:
key_t key1;
int msqid1;
int main(int arc, char *argv[])
{
getKeys();
queueCreate();
}
void getKeys()
{
if ((key1 = ftok(".", '1')) == -1)
{
perror("key1 creation");
exit(1);
}
}
void queueCreate()
{
if ((msqid1 = msgget(key1, 0666 | IPC_CREAT)) == -1)
{
perror("msqid1 creation");
exit(1);
}
}
抛出的错误是“msqid1 创建:权限被拒绝”。有什么想法吗?
I'm trying to create a queue, but I'm getting a permission denied error. I got this error before, but then I added code for error catching on the key creation and it was working. The only thing I've changed since then is I put my queue creation code in a separate function. Here's something like what my code looks like:
key_t key1;
int msqid1;
int main(int arc, char *argv[])
{
getKeys();
queueCreate();
}
void getKeys()
{
if ((key1 = ftok(".", '1')) == -1)
{
perror("key1 creation");
exit(1);
}
}
void queueCreate()
{
if ((msqid1 = msgget(key1, 0666 | IPC_CREAT)) == -1)
{
perror("msqid1 creation");
exit(1);
}
}
The error thrown is "msqid1 creation: Permission denied". Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最有可能的是,您在成功创建消息队列的那一次并没有销毁它,因此现在您无法重新创建它,因为它仍然存在。
您没有表明您所在的平台。通常,您可以使用
ipcs
命令获取各种 IPC 系统(共享内存、信号量和消息队列)的状态,并使用ipcrm
删除不再需要。Most likely you didn't destroy the message queue on the one occasion it was successfully created, so now you can't recreate it because it still exists.
You don't indicate which platform you're on. Classically, you'd use the
ipcs
command to obtain the status of the various IPC systems (shared memory, semaphores, and message queues), andipcrm
to remove IPC systems that are no longer wanted.您的错误似乎是
EACCES
而不是EEXIST
。我的 linux 手册页说:这些条件你检查了吗?
您正在使用当前目录作为 ftok 的路径。也许更改为“/tmp”中的普通本地文件,而不是您的主文件夹(nfs?)。
Your error seems to be
EACCES
and notEEXIST
. My linux man page says:Did you check for these conditions?
You are using the current directory as a path for
ftok
. Maybe change to a plain local file in "/tmp" and not in your home folder (nfs?).