#!/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.... 
#
# CT Jan 14, 1998
# CW Jan 22, 1996


# remove the /tmp files
#----------------------
echo "  removing temp files dd_server.logfile & /tmp/dd.*"
rm -f /tmp/$DD_NAME
rm -f /tmp/dd_server.logfile
rm -f /tmp/dd.*

#
# removing the processes - some users might want to change these lines
# ----------------------------------------------------------------------
#

# Get all of my processes in format "pid,command",
# and look for lines with dd_garbage_d. Pick out
# the beginning pid number and kill.

  set me = `whoami`
  set i = `ps -ef -o pid,comm | grep dd_garbage_d`
  set mypid = `expr "$i" : '\([0-9]*\)'`
  kill -9 $mypid
  echo "  removing $me's garbage daemon (pid = $mypid) "

# semaphores and shared memory segments
# --------------------------------------------------------
echo "  removing semaphores and shared memory segments"

foreach i ("`ipcs -c | grep $me`")
  # -c option of ipcs lists creator's login and group names
  # now look at first char on line of my resources
  set ipcs_type = `echo $i | cut -c1`
  # if shared memory ...
  if ($ipcs_type == 'm') then
     set mem = `expr "$i" : 'm[ ]*\([0-9]*\)[ ]*0x'`
     ipcrm -m $mem
     echo "    ipcrm -m $mem "
  # else if semaphore ...
  else if ($ipcs_type == 's') then
     set sem = `expr "$i" : 's[ ]*\([0-9]*\)[ ]*0x'`
     ipcrm -s $sem
     echo "    ipcrm -s $sem "
  endif
end
