shmget 大小限制问题 [英] shmget size limit issue
问题描述
我有这段代码:
if ((shmid = shmget(key, 512, IPC_CREAT | 0666)) < 0)
{
perror("shmget");
exit(1);
}
每当我将数字设置为高于 2048 时,就会出现一个错误消息:
Whenever I set the number any higher than 2048, I get, an error that says:
shmget: Invalid argument
但是,当我运行 cat/proc/sys/kernel/shmall
时,我得到 4294967296
.
However when I run cat /proc/sys/kernel/shmall
, I get 4294967296
.
有人知道为什么会这样吗?提前致谢!
Does anybody know why this is happening? Thanks in advance!
推荐答案
Jerry 的评论是正确的,即使你没有玩过这些东西也很神秘:这个怎么样:EINVAL: ...存在具有给定键的段,但大小大于该段的大小.
"
The comment from Jerry is correct, even if cryptic if you haven't played with this stuff: "What about this: EINVAL: ... a segment with given key existed, but size is greater than the size of that segment.
"
他的意思是该段已经存在 - 这些段是持久的 - 它的大小为 2048.
He meant that the segment is already there - these segment are persistent - and it has size 2048.
您可以通过以下方式看到它:
You can see it among the other ones with:
$ ipcs -m
并且您可以通过以下方式删除您的细分受众群(注意:仅删除您的细分受众群):
and you can remove your segment (beware: remove your one only) with:
$ ipcrm -M <key>
之后,您应该可以将其创建得更大.
After that you should be able to create it larger.
这篇关于shmget 大小限制问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!