Two methods for implementing second-level scheduled tasks in Linux (crontab runs every second)

Source: Internet
Author: User

 

The first solution, of course, is to write a script running in the background to keep repeating, and then sleep for a period of time each time.

While true; do

 

Command

 

Sleep XX // interval seconds

 

Done

 

Solution 2: Use crontab.

We all know that the minimum granularity of crontab is minutes, but we can still use a work und to run it every second.

Run the following command every 20 seconds:

Crontab-e

* ***/Bin/date

* *** Sleep 20;/bin/date

* *** Sleep 40;/bin/date

Note: replace/bin/date with your command.

 

In this way, it is okay to process the scheduled task every several dozen seconds. If you run the task every one second, you have to add 60 records... If it runs every second, use solution 1.

Author shootyou

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.