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

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


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

#!/bin/bashME=`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;donefor id in $IPCS_S; do  ipcrm -s $id;donefor 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


This works on my Mac OS:

for n in `ipcs -b -m | egrep ^m | awk '{ print $2; }'`; do ipcrm -m $n; done


ipcs -s | grep $USERNAME | perl -e 'while (<STDIN>) { @a=split(/\s+/); print `ipcrm sem $a[1]`}'

or

ipcs -s | grep $USERNAME | awk ' { print $2 } ' | xargs ipcrm sem

Change $USERNAME to a real username.