The script is as follows:
#! /Bin/sh # Name of the process to be checked progress_name = "heihu_server" # ------------------------------- # function: checkprogress # function: Check whether a process exists # parameter: $1 --- Name of the process to be checked # Return Value: If 0 exists, otherwise 1 is returned. # ------------------------------------- checkprogress () {# Check whether the input parameter is valid if ["$1" = ""]; then return 1 fi # $ process_num get the number of specified process names, if the value is 1, 0 is returned, indicating normal. If the value is not 1, 1 is returned, indicating that an error exists, process_num = 'ps-Ef | grep "$1" | grep-V "grep" | WC-l' if [$ process_num-EQ 1] needs to be restarted; Then return 0 else return 1 fi} # Check whether the test instance already exists while [1]; do checkprogress "$ progress_name" RET =$? If [$ ret-EQ 1]; then Echo "The Progress: $ progress_name is dead, I will start it right now! "# Killall-9 $ progress_name exec./$ progress_name & fi sleep 1 echo" sleep .. "done
Shell script checks the program. If it fails, restart the program.