No matter how programs are not perfect, it is impossible to perfect, in theory, any procedure has a day, official operational procedures, especially server programs, once the core dump, consequences, have experience in server development Friends, I have experienced a deep night, and I have been awakened by the phone, and the hand is restarted. I have to be batch by the boss next day. Therefore, the automatic restart is important when the program is wrong. Here is a way to discuss Linux to implement an automatic restart program.
There are many ways to implement the program under Linux, here we introduce it to the book, automatically restart the script.
It is assumed that the program is required to be re-enabled, and we determine whether the program is normal by judging the number of processes.
Test, we will determine if the program is normal by judging the number of processes.
PS-EF | GREP "$ 1" | grep -v "grep" | WC -L is the number of processes that get $ 1 (Test in this example), and the script determines the next step according to the number of processes. Check the number of processes in the system in the system every 1 second through a dead cycle.
The code is as follows: Script Check
#! / bin / sh # ------------------------------------------- ----------------------------------- # Function: CheckProcess # Features: Check if a process exists # parameters: $ 1 --- To check the name # Returns: If there is a return 0, return 1. # -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------- CheckProcess () {# checks if the input parameter is valid if ["$ 1" = ""]; the return 1 Fi # $ process_num Get the number of the specified process name, to return 0, indicate normal, not 1 return 1, indicate There is a mistake, you need to restart process_num = `ps -ef | grep" $ 1 "| grep -v" grep "| wc -l`ness [$ process_num-eq 1]; the return 0 else return 1 fi} # Check Test instance Whether you already exist while [1]; do checkprocess "test" checkqq_ret = $? If [$ checkqq_ret -eq 1]; then # kills all TEST processes, can change the operation you need to do KILLALL -9 TEST EXEC. /TEST & Fi Sleep 1DONE
Script Start: Join the Limit Coredumpsize 102400, set the size of the Core File, once the program core dump, tracks can be found. Execute the Check script in the script in the background, you can save a lot of trouble,
#! / bin / cshlimit coreumpsize 102400./check &