swh:1:snp:cac5fb5e02e08ee7616a46f7bfbaeee022e40e15
Raw File
Tip revision: 5f869cdbac789cb15fcd795bffcb549e1f2ca07e authored by Mike Stewart on 06 August 2019, 00:46:11 UTC
Added skeleton LM131 rev 1 for reconstruction.
Tip revision: 5f869cd
SimStop
# This shell script stops all of the processes on a given list
# (environment variable PIDS) whenever any of them stops.

# What the "trap" does is to keep the scanning process from exiting if 
# ctrl-C is hit or the parent process is stopped.  However, because this will
# have been accompanied by stopping apps we're scanning for, we will 
# terminate anyway, but we'll do it after terminating apps rather than before.
trap "" 0 1 2 9 15 17 19 23
sleep 5

# Try to determine where GNU grep is.  Usually, this is just 'grep', but on
# Solaris it's 'ggrep', and 'grep' is something that doesn't have the
# options we need.  I tried checking the OSTYPE environment variable, but
# that variable doesn't seem to get set when SimStop is called from VirtualAGC.
# Checking for ggrep isn't a very good test, but it's the best I have at the
# moment.
if which ggrep
then
        GREP=ggrep
else
        GREP=grep
fi

echo GREP=$GREP

# Now we have a big loop that just keeps checking that all of the processes
# are running.  If not, we stop all of them and exit.
echo Scanning for program status of processes ${PIDS}
i=1
while [ $i -eq 1 ]
do
  sleep 1
  for n in ${PIDS}
  do
    # Note that on failure we do the check multiple times to be sure.  This
    # shouldn't be necessary, but I found after migrating from SuSE 9.0 to 9.1
    # that the following test sometimes says that the process has terminated
    # when it really hasn't.
    if [ 1 -ne `ps -U ${USER} | $GREP -E -c "(^| )${n} "` ]
    then
      if [ 1 -ne `ps -U ${USER} | $GREP -E -c "(^| )${n} "` ]
      then
	if [ 1 -ne `ps -U ${USER} | $GREP -E -c "(^| )${n} "` ]
	then
	  if [ 1 -ne `ps -U ${USER} | $GREP -E -c "(^| )${n} "` ]
	  then
	    if [ 1 -ne `ps -U ${USER} | $GREP -E -c "(^| )${n} "` ]
	    then
	      if [ 1 -ne `ps -U ${USER} | $GREP -E -c "(^| )${n} "` ]
	      then
		if [ 1 -ne `ps -U ${USER} | $GREP -E -c "(^| )${n} "` ]
		then
		  echo Process ${n} has terminated.
		  i=0
		fi
	      fi
	    fi
	  fi
	fi
      fi
    fi
  done
done
echo Bye! Shutting down the simulation.
for n in ${PIDS}
do
  kill ${n} >/dev/null
done


back to top