#!/bin/csh -f

# Usage: ipcrmall <user>
# Remove all regions for user <user>

# Destroy all the shared memory regions on the machine (of course,
# only those are destroyed for which permission is available)
 
if ($#argv != 1) then
   echo "Usage: ipcrmall <username>"
   exit -1
   endif

set info = "`ipcs -m`"
set num = $#info
@ num_destroyed = 0

@ count = 3
while ($count <= $num)
      set id = `echo $info[$count]`
      if ($id[5] == $argv[1]) then
          ipcrm -m $id[2]
	  @ num_destroyed++
      endif
      @ count++
      end

if ($num_destroyed == 0) then
    echo "No shared memory region for user $argv[1] found"
    endif
