天天看點

【轉】使用ipcrm指令為什麼不能釋放shared memory?https://access.redhat.com/solutions/39532Why shared memory can not be released by "ipcrm" command ?

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

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

 SOLUTION 已驗證 - 已更新  2014年八月17日04:04  -   English 

環境

  • 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
           



繼續閱讀