#! /Bin/sh Echo "'date '" Echo "Start $0 ---------" Echo "" # Monitoring every 10 seconds Sec = 10 # Obtain the specified process name mainAPP, memory usage, process running status, and process name Eval $ (ps | grep "mainApp" | grep-v grep | awk {'printf ("memInfo = % s; myStatus = % s; pName = % s", $3, $4, $5 )'}) Echo $ pName $ myStatus $ memInfo TestPrg = "" While [-n "$ pName"-a "$ myStatus "! = "Z"] Do Echo "---------- 'date '---------------------" Echo $ pName $ myStatus $ memInfo Sleep $ sec #### You must initialize them again !!!!! PName = "" MyStatus = "" MemInfo = "" Eval $ (ps | grep "mainApp" | grep-v grep | awk {'printf ("memInfo = % s; myStatus = % s; pName = % s", $3, $4, $5 )'}) TestPrg = 'ps | grep "MyTester" | grep-v grep | awk '{print $0 }'' If [-z "$ testPrg"]; then Break Fi # Be sure to initialize it again as null TestPrg = "" Done Echo "End $0 --- ($ pName, $ myStatus, $ testPrg )-------------------" If [-z "$ pName"]; then ### Stop the test program after the tested program exits unexpectedly Killall MyTester Echo "stop TestProgram MyTester" Fi Echo "'date '" Echo "--------------- Current Status ------------------" Ps | grep-E "mainApp | SubApp" | grep-v grep Echo "" |