【转】使用ipcrm命令为什么不能释放shared memory?

https://access.redhat.com/solutions/39532

Why shared memory can not be released by "ipcrm" command ?

 SOLUTION 已验证 - 已更新  2014年八月17日04:04  -  

环境

  • Red Hat Enterprise Linux 5
  • Red Hat Enterprise Linux 6
  • Shared Memory
  • ipcrm, ipcs

问题

  • Why shared memory can not be released by "ipcrm" command ?
  • How to remove shared memory segment ?
  • What is the meaning of the "dest" seen under status from the output of the "ipcs -m" command ?

Eg:

  • The shared memory segment (4685833) is marked to be destroyed on the system.
Raw
# ipcs -m
------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status      
0x74000157 3473408    root      600        4          0                       
0x7400012d 4161537    root      600        4          0                       
0x74000190 851970     root      600        4          0                       
0x00000000 4521987    root      644        80         2                       
0x7400012c 4128772    root      600        4          0                       
0x00000000 4554757    root      644        16384      2                       
0x00000000 4587526    root      644        280        2                       
0x00000000 4620295    root      644        64         2          dest         
0x00000000 4653064    root      644        16384      2          dest         
0x00000000 4685833    root      644        280        2          dest         
  • Tried to remove shared memory segment with shmid (4685833) using ipcrm command.
Raw
# ipcrm -m 4685833
  • The shared memory segment with shmid (4685833) still present.
Raw
# ipcs -m
------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status      
0x74000157 3473408    root      600        4          0                       
0x7400012d 4161537    root      600        4          0                       
0x74000190 851970     root      600        4          0                       
0x00000000 4521987    root      644        80         2          dest         
0x7400012c 4128772    root      600        4          0                       
0x00000000 4554757    root      644        16384      2                       
0x00000000 4587526    root      644        280        2                       
0x00000000 4620295    root      644        64         2          dest         
0x00000000 4653064    root      644        16384      2          dest         
0x00000000 4685833    root      644        280        2          dest 

决议

  • Status "dest" in the output of "ipcs -m" means memory segment is marked to be destroyed and "nattach" field shows that how many application being attached to the shared memory.
Raw
# ipcs -m
------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status      
0x74000157 3473408    root      600        4          0                       
0x7400012d 4161537    root      600        4          0                       
0x74000190 851970     root      600        4          0                       
0x00000000 4521987    root      644        80         2                       
0x7400012c 4128772    root      600        4          0                       
0x00000000 4554757    root      644        16384      2                       
0x00000000 4587526    root      644        280        2                       
0x00000000 4620295    root      644        64         2          dest         
0x00000000 4653064    root      644        16384      2          dest         
0x00000000 4685833    root      644        280        2          dest         
                                                      ^           ^
                                                      |           +-----[ Memory segment is marked to be destroyed ]
                                                      +-----------------[ Number of application being attached to the shared memory ]
  • The shared memory segment marked as "dest" will be released its memory when all the application which are attached with this memory segment are terminated.

Steps to remove shared memory segment:

1) Determine the application pid's which are using the shared memory segment. The process id can be identified using;
Eg:

Raw
# ipcs -mp

or

# grep -l "shmid" /proc/[1-9]*/maps

or

# lsof | egrep "shmid"

2) Terminate all application pid's which are using shared memory segment.
Eg:

Raw
# kill -15 <pid>

3) Use "ipcrm" command to remove the shared memory segment.
Eg:

Raw
# ipcrm -m shmid

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值