#! /bin/sh #------------------------------------------------------------------------------- # Remove all shared memory segments and semaphores belonging to the # current non-root user (as determined by $USER) on a Linux system. # # Irv.Elshoff@Deltares.NL # 10 oct 96 # 22 sep 10 # # Copyright (C) Stichting Deltares, 2011-2012. #------------------------------------------------------------------------------- if [ `uname` != "Linux" ]; then echo "$0 runs on Linux only" exit 1 fi if [ "$USER" == "root" ]; then echo "$0 cannot be used by root; use ipcrm instead" exit 1 fi awkstr="\$3 == \"$USER\" {print \$2}" for id in `ipcs | awk "$awkstr"`; do # We don't know whether awk found a shared memory segment or a semaphore, # but by attempting to delete both, at least one will succeed (and both # if the ID is the same for both SM and sem, which does happen). ipcrm -m $id > /dev/null 2>&1 if [ $? -eq 0 ]; then echo "Removed shared memory segment $id" fi ipcrm -s $id > /dev/null 2>&1 if [ $? -eq 0 ]; then echo "Removed semaphore $id" fi done