#!/bin/bash

# This script finds TRC GUI and kills it and any children
# It should normally be used only in CyFlex go script.

__find_trc_gui()
{
   /bin/ps axh -o pid,cmd | while read pid cmd; do
      echo "$cmd" | grep java | grep trc.MainGUI > /dev/null;
      [ $? -eq 0 ] && echo $pid;
   done
}

pid=`__find_trc_gui`
if [ -z "$pid" ]; then
    echo "No prior TRC GUI found to terminate.";
    exit 1;
fi

echo Found TRC GUI with PID = $pid.  Terminating it.
/cyflex/cmds/trc/trc_kill_tree.sh -15 $pid
