#!/bin/csh
#
# This script will kill all the processes that might be
# associated with the DD system after a hang
# It is quick and dirty.... 
#
# CW Jan 22, 1996
#

#
# removing the processes - some users might want to change these lines
# ----------------------------------------------------------------------
#
echo "removing all processes ..."
set me = `whoami`
@ n = 0
ps -u $me  -o pid,comm | grep -i dd

foreach i (`ps -u $me -o pid,comm | grep -i dd | sed '/dd_clean/d'`)
        @ n += 1
        @ k = $n % 2
        if ( $k == 1 ) then
                echo " killing process $i"
                kill -9 $i
        endif
end



# semaphores and shared memory segments
# --------------------------------------------------------
echo "removing all semaphores and shared memory segments"
rm -f /tmp/ipcs.tmp
ipcs > /tmp/ipcs.tmp
foreach i ("`cat /tmp/ipcs.tmp`")
	set ipcs_type = `echo $i | cut -c1`
	if ($ipcs_type == 'm') then
     set ipcmd = `echo $i | cut -f1,2 -d" "`
     echo ipcrm -"$ipcmd"
	  ipcrm -`echo $i | cut -f1,2 -d" "`
	else if ($ipcs_type == 's') then
     set ipcmd = `echo $i | cut -f1,2 -d" "`
     echo ipcrm -"$ipcmd"
	  ipcrm -`echo $i | cut -f1,2 -d" "`
	endif
end
rm -f /tmp/ipcs.tmp


# remove the /tmp files
#----------------------
rm -f /tmp/dd_server.logfile
rm -f /tmp/dd.*




