Using cron to monitor background process status

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.