Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 313
simone Avatar asked Jan 26 '10 23:01

simone


People also ask

How do you remove a semaphore?

Access the MEMORY application menu as described in Accessing KM Commands and InfoBoxes. Select Remove Semaphores. BMC PATROL displays the Remove Semaphores dialog box. Type the numeric ID in the Semaphore ID field and click either Apply or Apply To Selected.

What is system V semaphores?

Semaphores let processes query or alter status information. They are often used to monitor and control the availability of system resources such as shared memory segments. Semaphores can be operated on as individual units or as elements in a set.

What is difference between shared memory semaphore?

The semaphore is a system for synchronization 2 or plus process to access a shared resource. The shared memory is a system for sharing a piece of memory between 2 o plus process, on the shared memory is possible write or read data to and from a process.


2 Answers

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

like image 56
neverMind Avatar answered Sep 20 '22 16:09

neverMind


This works on my Mac OS:

for n in `ipcs -b -m | egrep ^m | awk '{ print $2; }'`; do ipcrm -m $n; done 
like image 25
Serge Avatar answered Sep 17 '22 16:09

Serge