printf("parent:pid is %d,share memory from %lx to %lx, content:%s\n",getpid(),(unsigned long)shmptr, (unsigned long)(shmptr + SIZE ), shmptr); printf("parent process sleep 2 seconds\n"); sleep(2); if((shmctl(shmid, IPC_RMID, 0) < 0)) { printf("shmctl error:%s\n", strerror(errno)); exit(-1); } } waitpid(pid,NULL,0); exit(0); } 输出为: shmctl(shmid, IPC_RMID, 0)的作用是从系统中删除该恭喜存储段。因为每个共享存储段有一个连接计数(shmid_ds结构中的shm_nattch),所以除非使用该段的最后一个进程终止与该段脱接,否则不会实际上删除该存储段 |