免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 5282 | 回复: 3
打印 上一主题 下一主题

[函数] shmget返回值问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-06-24 09:08 |只看该作者 |倒序浏览
程序中调用shmget,结果返回值总是0,是什么原因,盼赐教

论坛徽章:
0
2 [报告]
发表于 2008-06-24 09:14 |只看该作者
RETURN VALUES

  Upon successful completion, a shared memory identifier is returned.  If the
  shmget() function fails, a value of -1 is returned and errno is set to
  indicate the error.
ERRORS

  The shmget() function sets errno to the specified values for the following
  conditions:

  [EACCES]
      A shared memory region ID already exists for the key parameter, but
      operation permission as specified by the low-order nine bits of the
      flags parameter was not granted.

  [EEXIST]
      A shared memory region ID already exists for the key parameter, but
      IPC_CREAT and IPC_EXCL were specified for the flags parameter.

  [EINVAL]
      The value of the size parameter is less than the system-defined minimum
      or greater than the system-defined maximum. Or, a shared memory region
      ID already exists for the key parameter, but the number of bytes allo-
      cated for the region is less than size and size is not equal to 0
      (zero).

  [ENOENT]
      A shared memory region ID does not exist for the key parameter, and
      IPC_CREAT was not used for the flags parameter.

[ENOMEM]
     An attempt was made to create a shared memory region ID and its associ-
     ated shmid_ds structure, but there was not enough physical memory
     available.

[ENOSPC]
     An attempt to create a new shared memory region ID exceeded the
     system-wide limit on the maximum number of IDs allowed.

检查一下

论坛徽章:
0
3 [报告]
发表于 2008-06-24 09:20 |只看该作者
谢谢gawk。不过函数没有返回-1,而是返回0,表面上没有错误,然而shmid为0的话实际还是不可用的,所以比较困惑,什么情况下会返回0呢?

论坛徽章:
0
4 [报告]
发表于 2008-06-24 09:43 |只看该作者
单从0来判断,不能判断为错误


我遇到过0

手动删除share memory后,你会发现这个值有变化

另外,注意权限
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP