分类: LINUX
2010-05-07 17:58:20
在unix/linux下,经常有因为共享内存、信号量,队列等共享信息没有干净地清楚而引起一些问题。
查看共享信息的内存的命令是ipcs [-m|-s|-q]。
默认会列出共享内存、信号量,队列信息,-m列出共享内存,-s列出共享信号量,-q列出共享队列。
怎样清楚呢?
清楚命令是ipcrm [-m|-s|-q] id。
-m 删除共享内存,-s删除共享信号量,-q删除共享队列。
下面是一个操作示例:
view plaincopy to clipboardprint?
[ora@localhost ora]$ ipcs
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x0399ef4c 262145 ora 660 255852544 55
------ Semaphore Arrays --------
key semid owner perms nsems
0x965bd64c 884736 ora 660 154
------ Message Queues --------
key msqid owner perms used-bytes messages
[ora@localhost ora]$ ipcs
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x0399ef4c 262145 ora 660 255852544 50
------ Semaphore Arrays --------
key semid owner perms nsems
0x965bd64c 884736 ora 660 154
------ Message Queues --------
key msqid owner perms used-bytes messages
[ora@localhost ora]$ ipcrm -m 262145
[ora@localhost ora]$ ipcrm -s 884736
[ora@localhost ora]$ ipcs
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
------ Semaphore Arrays --------
key semid owner perms nsems
------ Message Queues --------
key msqid owner perms used-bytes messages
[ora@localhost ora]$ ipcs -m
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
[ora@localhost ora]$ ipcs -s
------ Semaphore Arrays --------
key semid owner perms nsems
[ora@localhost ora]$ ipcs -q
------ Message Queues --------
key msqid owner perms used-bytes messages
[ora@localhost ora]$ ipcs
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x0399ef4c 262145 ora 660 255852544 55
------ Semaphore Arrays --------
key semid owner perms nsems
0x965bd64c 884736 ora 660 154
------ Message Queues --------
key msqid owner perms used-bytes messages
[ora@localhost ora]$ ipcs
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x0399ef4c 262145 ora 660 255852544 50
------ Semaphore Arrays --------
key semid owner perms nsems
0x965bd64c 884736 ora 660 154
------ Message Queues --------
key msqid owner perms used-bytes messages
[ora@localhost ora]$ ipcrm -m 262145
[ora@localhost ora]$ ipcrm -s 884736
[ora@localhost ora]$ ipcs
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
------ Semaphore Arrays --------
key semid owner perms nsems
------ Message Queues --------
key msqid owner perms used-bytes messages
[ora@localhost ora]$ ipcs -m
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
[ora@localhost ora]$ ipcs -s
------ Semaphore Arrays --------
key semid owner perms nsems
[ora@localhost ora]$ ipcs -q
------ Message Queues --------
key msqid owner perms used-bytes messages
在上面示例示例中:
首先用ipcs命令列出了共享内存、共享队列,共享信号量。
显示出当前系统中有共享内存,共享信号量,没有共享队列。
然后执行ipcrm -m 262145清楚共享semid=262145的共享内存。
执行ipcrm -s 884736清楚共享信号量semid=884736的共享信号量。
最后执行ipcs查看共享内存、共享队列,共享信号量信息,发现全都没有了,说明上面的ipcrm清楚共享内存和共享信号量成功。