ipcs - provide information on ipc facilities
DESCRIPTION
ipcs provides information on the ipc facilities for which the calling process has read access.
The -i option allows a specific resource id to be specified. Only information on this id will be printed.
Resources may be specified as follows:
-m shared memory segments
-q message queues
-s semaphore arrays
-a all (this is the default)
The output format may be specified as follows:
-t time
-p pid
注:
key栏中列出的信息是应用程序定义的键值,如果是私有对象的键值则为0,在这里我们定义键值为12345678,也就是输出的0x00bc614e(十六进制)
shmid栏中列出共享内存的ID,这个值是唯一的.
owner栏中列出创建共享内存的用户是root.
perms栏中列出共享内存的权限.
bytes栏中列出这块共享内存的大小,我们通过调用sysconf(_SC_PAGE_SIZE)得到要创建的共享内存大小为4096个字节.
nattch栏中列出连接在关联的共享内存段的进程数.
status栏中列出当前共享内存的状态,当该段内存的mode字段设置了SHM_DEST位时就会显示"dest"字样,
当用户调用shmctl的IPC_RMID时,内核首先看有多少个进程还和这段内存关联着,如果关联数为0,就会销毁(释放)这段内存,否则就设置这段内存的mode位SHM_DEST,
并设置它的key为IPC_PRIVATE,这意味着关联着的进程仍可合法存取这端内存,但是它不能再被新的进程关联了.
在上面的输出中,我们没有看到smem用到的共享内存有dest的状态,而此时我们用ipcrm -m 18874397手工删除该段共享内存时,
此时该段的共享内存键值将会是0x00000000(IPC_PRIVATE),而程序通过调用shmdt来释放该段共享内存时,这段共享内存才会真正的消失.
来源: http://www.bubuko.com/infodetail-1869029.html