#!/bin/bash
# ENV Variables
SCRIPTDIR=$HOME/Scripts/BASH
# check if topspin closed properly. If not, identify and kill the children of cpr first
if [[ -n $(ps -C cpr -o pid=) ]]; then
flagcpr=$(ps -C cpr -o pid=)
cprparent=$(ps --pid $flagcpr -o ppid=)
if [[ -n $(ps --ppid $flagcpr -o pid=) ]]; then
tmpflg=$(ps --ppid $flagcpr -o pid=)
kill -s SIGHUP $tmpflg
fi
# Now kill the parent process i.e. cpr
kill -s SIGHUP $flagcpr
# Demise of cpr stops at an interactive prompt;
# to move beyond and enable a clean session end, kill parent of cpr
kill -s SIGHUP $cprparent
#
# Make sure the desktop session is ended
kill -s SIGHUP $(ps -C icewm-session -o pid=)
date >> $SCRIPTDIR/toplog
echo 'topspin terminated' >> $SCRIPTDIR/toplog
$SCRIPTDIR/banner "TRMinated"
# $SCRIPTDIR/banner "TRMinated" > /dev/null
else
$SCRIPTDIR/banner "NO Topspin"
#$SCRIPTDIR/banner "NO Topspin" > /dev/null
fi