用ipcrm删除共享内存

时间:2013-05-26 18:44:50

标签: linux ipcs

我正在分配一些具有特定烫发“644”的共享内存和消息队列。

手动删除它们是一项艰苦的工作,所以我想知道如何删除具有特定烫发644的所有行。

e.g

------共享内存段-------- key shmid owner perms bytes nattch status
0x00000000 0 benny 600 33554432 2 dest
0x00000000 229377 benny 644 52 0

------信号量数组-------- 密钥semid所有者perms nsems

------消息队列-------- 密钥msqid所有者perms used-bytes消息
0x2731af4c 262144 benny 644 840 30
0x0756d9c1 294913 benny 644 16380 585
0x2d1b2cc7 327682 benny 644 0 0

0x343dccc1 360451 benny 644 0 0

感谢。

2 个答案:

答案 0 :(得分:0)

您必须使用脚本来执行此操作,例如

#!/bin/bash

m=`ipcs -m | grep -w 644 | cut -d' ' -f2`
for i in $m
do
        echo removing shm id $i
        ipcrm -m $i
done

s=`ipcs -s | grep -w 644 | cut -d' ' -f2`
for i in $s
do
        echo removing sem id $i
        ipcrm -s $i
done

q=`ipcs -q | grep -w 644 | cut -d' ' -f2`
for i in $q
do
        echo removing queue id $i
        ipcrm -q $i
done

答案 1 :(得分:0)

ipcs -a | awk '{ \
  if ($3=="Memory")    ARG="-m"; \
  if ($3=="Semaphore") ARG="-s"; \
  if ($3=="Message")   ARG="-m"; \
  if ($4=="644")      system ("ipcrm "ARG" "$2""); \
  }'