In the previous blog, the implementation of the automated test program was written, and now the developer needs to know the running state of the process that was tested (in this case, the main process running on Linux) before the exception exited, such as memory usage, CPU usage, and so on.
The running state of the specified process is now implemented with a shell script.
directly on the code.
#!/bin/shEcho "' Date '"Echo "Start ---------"Echo ""#每十秒监视一下Sec=Ten#取得指定进程名为mainAPP, memory usage, process run state, process nameEval$ (PS | grep"Mainapp"| Grep-v grep | awk {' printf ("meminfo=%s;mystatus=%s;pname=%s", $3,$4,$5) '})Echo $pName $myStatus $memInfotestprg="" while[-N"$pName" -A "$myStatus"!="Z"] Do Echo "----------' Date '---------------------" Echo $pName $myStatus $memInfoSleep$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 $} '`if[-Z"$testPrg"]; Then Break fi # #注意一定要再次初始化为空testprg="" DoneEcho "End $---($pName,$myStatus,$testPrg)-------------------"if[-Z"$pName"]; Then # # #发现测被测试程序异常退出后, stop the test programKillall MytesterEcho "Stop Testprogram mytester"fiEcho "' Date '"Echo "---------------current Status------------------"PS | Grep-e"mainapp| Subapp "| Grep-v grepEcho ""
This realizes that every 10s reads the status of the process, and then displays, when the discovery process exists and the state is non-Z (non-zombie), continue to monitor, but when the test program completed or an abnormal exit, the script will also exit the monitoring loop, after exiting the loop, print out the status of the specified process.
Note: Use of the eval directive
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Monitoring of shell scripts specifies the running state of a process