linux - 删除类 UNIX 系统上的所有 SYSTEM V 共享内存和信号量

标签 linux unix posix semaphore shared-memory

如何在类 UNIX 系统(例如 Ubuntu)上使用单个命令删除所有未使用的信号量和共享内存?

最佳答案

在这里,保存并在你的 shell 上尝试这个脚本 (kill_ipcs.sh):

#!/bin/bash

ME=`whoami`

IPCS_S=`ipcs -s | egrep "0x[0-9a-f]+ [0-9]+" | grep $ME | cut -f2 -d" "`
IPCS_M=`ipcs -m | egrep "0x[0-9a-f]+ [0-9]+" | grep $ME | cut -f2 -d" "`
IPCS_Q=`ipcs -q | egrep "0x[0-9a-f]+ [0-9]+" | grep $ME | cut -f2 -d" "`


for id in $IPCS_M; do
  ipcrm -m $id;
done

for id in $IPCS_S; do
  ipcrm -s $id;
done

for id in $IPCS_Q; do
  ipcrm -q $id;
done

每当我们在大学生服务器上运行 IPCS 程序时,我们都会使用它。有些人并不总是清理所以......需要它:P

关于linux - 删除类 UNIX 系统上的所有 SYSTEM V 共享内存和信号量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2143404/

相关文章:

linux - 使用TSP100打印机从命令行打印HTML页面

c - 父局部变量充当三个 child 之间的共享变量

C11 相当于 POSIX flockfile()?

c++ std::string.find 在 boolean 表达式中返回意外结果

linux - Posix 消息队列和命令行?

linux - "service postgresql start"和 "pg_ctl start"有什么区别?

linux - 如何确定 NTP 通信状态

c++ - 在 linux 中调用 socket.close 后 socket.read_some 需要很长时间才能返回

regex - 使用 grep 查找以 $ 开头的模式

bash - shell 中的变量插值