Delete all SYSTEM V shared memory and semaphores on UNIX-like systems

前端 未结 11 2473
情话喂你
情话喂你 2020-12-23 14:01

How can I delete all not used semaphores and shared memory with a single command on a UNIX-like system, e.g., Ubuntu?

11条回答
  •  旧时难觅i
    2020-12-23 14:58

    Here, save and try this script (kill_ipcs.sh) on your shell:

    #!/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
    

    We use it whenever we run IPCS programs in the university student server. Some people don't always cleanup so...it's needed :P

提交回复
热议问题