Blame src/env/rmshm

Packit 0848f5
#! /bin/sh
Packit 0848f5
# courtesy of Jarek Nieplocha, to clean ipc's
Packit 0848f5
# Modified by Bill Gropp to apply only to calling user
Packit 0848f5
ipccmd=ipcrm
Packit 0848f5
username=`whoami`
Packit 0848f5
for arg in "$@" ; do
Packit 0848f5
   case $arg in
Packit 0848f5
	-help|-u|-us*|-h)
Packit 0848f5
	echo "cleanipcs [-show] [-echo]"
Packit 0848f5
	exit 1
Packit 0848f5
	;;
Packit 0848f5
	-echo)
Packit 0848f5
	set -x
Packit 0848f5
	;;
Packit 0848f5
	-show)
Packit 0848f5
	ipccmd="echo ipcrm"
Packit 0848f5
	;;
Packit 0848f5
	*)
Packit 0848f5
	if [ -n "$arg" ] ; then
Packit 0848f5
  	    echo "Unrecognized argument $arg"
Packit 0848f5
	    exit 1
Packit 0848f5
	fi
Packit 0848f5
	;;
Packit 0848f5
   esac
Packit 0848f5
done
Packit 0848f5
#
Packit 0848f5
# LINUX uses an incompatible form of the ipcrm command!  Try to detect this
Packit 0848f5
# An earlier version looked at the output of ipcrm, but that output
Packit 0848f5
# keeps changing.  The following code from Ralf Wildenhues attempts to 
Packit 0848f5
# use the Linux /proc interface instead.
Packit 0848f5
#statvalue=`ipcrm 2>&1`
Packit 0848f5
#if [ $? != 0 ] ; then 
Packit 0848f5
#    if [ "$statvalue" = 'usage: ipcrm [shm | msg | sem] id' ] ; then
Packit 0848f5
#        UseLinux=1
Packit 0848f5
#    fi
Packit 0848f5
#fi
Packit 0848f5
#if [ $UseLinux = 0 ] ; then
Packit 0848f5
if [ x`uname -s` = xLinux ] ; then
Packit 0848f5
    # try to use /proc interface if possible
Packit 0848f5
    # and hope it does not change too often
Packit 0848f5
    if [ -r /proc/sysvipc/shm  ] ; then
Packit 0848f5
    	cat /proc/sysvipc/shm \
Packit 0848f5
	| gawk '{if ($8 == uid) printf("%s %s\n", comm, $2)}' uid=$UID comm="$ipccmd shm " \
Packit 0848f5
	| sh > /dev/null
Packit 0848f5
    else
Packit 0848f5
	ipcs -m \
Packit 0848f5
	| gawk '{if ($3 == name) printf("%s %s\n", comm, $2)}' name=$username comm="$ipccmd shm " \
Packit 0848f5
	| sh > /dev/null
Packit 0848f5
    fi
Packit 0848f5
    if [ -r /proc/sysvipc/sem ] ; then
Packit 0848f5
    	cat /proc/sysvipc/sem \
Packit 0848f5
	| gawk '{if ($5 == uid) printf("%s %s\n", comm, $2)}' uid=$UID comm="$ipccmd sem " \
Packit 0848f5
	| sh > /dev/null
Packit 0848f5
    else
Packit 0848f5
	ipcs -s \
Packit 0848f5
	| gawk '{if ($3 == name) printf("%s %s\n", comm, $2)}' name=$username comm="$ipccmd sem " \
Packit 0848f5
	| sh > /dev/null
Packit 0848f5
    fi
Packit 0848f5
else
Packit 0848f5
    $ipccmd `ipcs | awk '{if ((($1 == "m") || ($1 == "s")) && ($5 == "'$username'")) print sprintf("-%s %s",$1,$2) }'`
Packit 0848f5
fi
Packit 0848f5
#
Packit 0848f5
# Here is the old LINUX code
Packit 0848f5
#    #
Packit 0848f5
#    # For LINUX, we need this instead:
Packit 0848f5
#    ipcs -m | gawk '{if ($3 == name) printf("%s %s\n", comm, $2)}' name=$username comm="$ipccmd shm " | sh > /dev/null
Packit 0848f5
#    ipcs -s | gawk '{if ($3 == name) printf("%s %s\n", comm, $2)}' name=$username comm="$ipccmd sem " | sh > /dev/null
Packit 0848f5
#
Packit 0848f5
# mpirun could call this for systems that use SYSV shared memory features,
Packit 0848f5
# just to keep them friendly.
Packit 0848f5
Packit 0848f5