#!/bin/csh
#--------------------------->  C shell - script  <----------------------------#
#- Copyright (C) 199x by International Computer Science Institute            -#
#- This file is part of the GNU Sather package. It is free software; you may -#
#- redistribute  and/or modify it under the terms of the  GNU General Public -#
#- License (GPL)  as  published  by the  Free  Software  Foundation;  either -#
#- version 3 of the license, or (at your option) any later version.          -#
#- This  program  is distributed  in the  hope that it will  be  useful, but -#
#- WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY -#
#- or FITNESS FOR A PARTICULAR PURPOSE. See Doc/GPL for more details.        -#
#- The license text is also available from:  Free Software Foundation, Inc., -#
#- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA                     -#
#------------->  Please email comments to <bug-sather@gnu.org>  <-------------#

#
# 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





