using cron to monitor background process status
http://blog.csdn.net/dyx810601/article/details/72967758
1.
Use cron to monitor the status of the background process and automatically pull the process out if the process dies or the server restarts.
Purpose: The server program under Linux will be dropped for various reasons, it will affect the user's use, here provides a simple process monitoring and restart function.
Implementation principle: By the Scheduled task crontab call script, the script with PS check whether the process exists, if not exist then restart and write to the log.
Call the script every minute cron_worker.sh
$crontab-E
*/1 * * * * sudo bash/home/test/onlineadsdemo/bin/cron_worker.sh
View cron Start schedule: $crontab-L
The first is the script execution, but error: in the crontab operation, the results found no results, view the/var/log/message log, found that crontab has executed, but failed. manual operation is possible, put in crontab inside found can not run.
Processing method: Do not use relative path in the script, all change to absolute path
The second is to edit the /var/spool/cron/user user to execute the username, typically root
If the change does not work, reload cron: Treatment method: /etc/init.d/cron Reload
The third type is edited with Crontab-e
Use the following command add entries to crontab should take effect right away. #crontab-E
If not yet, from its service: Treatment method:/etc/init.d/crond restart |
Finally, be sure to restart Cron:$/etc/init.d/cron start
2. Thecron_worker.sh script is as follows:
Linux command (+): Bash Shell Get Process PID
Http://www.cnblogs.com/lovychen/p/6211209.html
Summary of crontab Scheduled tasks not automatically performed
Http://www.cnblogs.com/wang3680/p/5383645.html
Using cron to monitor background process status