#!/bin/csh
#
# This script comes from the original TAM distribution 
# (TCP/IP Active Message Library). It has not been tested
# with this version of the library and may or may not
# work on your machine.
#
# Split-c process kill utility
#
set task=$argv[1]
set opt1="grep $USER"
set opt2="grep $argv[1]"
set opt3="grep -v rsh"
set opt4="grep -v csh"
set opt5="grep rsh"
set opt6="grep -v grep"

set splitpids=`/usr/bin/ps -ef|$opt1|$opt2|grep -v grep|$opt3|$opt4|cut -c9-14`
echo "   Cleaning up for host: $HOSTNAME"
#if (`test -n $splitpids`) kill -9 $splitpids[2]
foreach killpid ($splitpids[*])
  kill -9 $killpid
  echo "      Killed split-c process $killpid"
  end


set splithosts=`cat $TCPAM_CONFIG | egrep "^[a-z,A-Z]" | cut -f1 -d" "`
foreach thishost ($splithosts[*])
   set splitpids=`/usr/bin/ps -ef|$opt1|$opt2|grep $thishost|$opt6|cut -c9-14`
   echo "   Cleaning up for host: $thishost"
   foreach killpid ($splitpids[*])
    kill -9 $killpid
   echo "      Killed split-c process $killpid"
   end
   set splitpids=`rsh $thishost /usr/bin/ps -ef|$opt1|$opt2|$opt4|$opt6|grep -v pkill|cut -c9-14`
   foreach killpid ($splitpids[*])
    rsh $thishost kill -9 $killpid
    echo "      Killed remote split-c process $killpid"
   end
end





