【问题标题】:Shmget: Invalid argument. Why i get this error?Shmget:无效的参数。为什么我会收到此错误?
【发布时间】:2011-12-08 10:27:37
【问题描述】:

我在尝试执行这部分代码时收到“shmget: Invalid argument error”

  int *nFS, *spb, *cell1, shmid;
  key_t key = 5768; 

  //i need a shared memory segment in which i can put 3 ints
  if ((shmid = shmget(key, (sizeof(int) * 3), IPC_CREAT | 0666)) < 0 ) {
             perror("shmget");
             exit(1);
       } 
 if ((spb = (int)shmat(shmid, NULL, 0))== -1 ){  
            perror("shmat");
            exit(1);
      }
  cell1= spb + 1 ;
  nFS= cell1 + 1;
  //i try to assign here 7 to  nFS
  *nFS=7;

这里出了点问题,但我不知道是什么。你能帮助我吗?

谢谢,亚历克斯。

【问题讨论】:

  • 和你一样有问题的人cboard
  • 你要求的太少了!

标签: c memory pointers shared


【解决方案1】:

来自 shmget(1) 手册页:

EINVAL 一个新的段被创建并且大小 SHMMAX,或者没有新的细分市场 已创建,具有给定键的段存在,但大小大于该段的大小。

您应该使用ipcs 检查您是否仍有此键的段,并使用ipcrm 将其删除。

【讨论】:

  • 我可以使用不同的方式为键赋值以获得更大的可用内存空间吗?
猜你喜欢
  • 2011-10-08
  • 2022-01-18
  • 1970-01-01
  • 2018-10-24
  • 2018-06-22
  • 2016-01-01
  • 2017-11-30
相关资源
最近更新 更多