- 论坛徽章:
- 0
|
小弟初学编程,有一个关于system V Share memory的疑问,在此向大虾请教。
我想测试我最大能得到多少个shm的id.写了如下程式。
- #include <sys/types.h>;
- #include <unistd.h>;
- #include <sys/ipc.h>;
- #include <sys/shm.h>;
- #define MAXLIST 1000
- int shmlist[MAXLIST];
- int main(int argc,char **argv)
- {
- int i,n;
- for(i=0;i<MAXLIST;i++){
- if((shmlist[i]=shmget(IPC_PRIVATE,1,IPC_CREAT))<0)
- break;
- }
- printf("Your Limits is:%d \n",i);
- for(n=0;n<i;n++){
- if(shmctl(shmlist[n],IPC_RMID,NULL)<0)
- errx(1,"error when remove shm id.\n");
- }
- exit(0);
- }
复制代码
编译运行如下
- $ sysctl kern.ipc.shmmni kern.ipc.shmseg //查看系统限制值
- kern.ipc.shmmni: 192
- kern.ipc.shmseg: 128
- $ ./a.out
- Your Limits is:189 //程序的输出值
- $
复制代码
为什么我得到的限制是192-4(另外3个为其它程式占用),而不是 128-4 ?[/code] |
|