Cron: does cron work every 1 second?

How can I run cron every 1 second? only minus is used by default

+4
source share
3 answers

Let cron run once, for the first time. Put the program in an infinite loop, sleep () for 1 second at the end of each loop. like this, in C:

int main( int argc, char ** argv ) { while (1) { // do the work sleep(1000); } } 

Could this work?

+8
source

Cron runs stuff every minute. Use script:

  while:
 do
     sleep 1
     some_command ||  break
 done

or in one line:

  while:;  do sleep 1;  some_command ||  break;  done 

This will wait 1 second between each execution, so if your command takes 0.75 seconds to run, then this script will run it every 1.75 seconds.

+3
source

You cannot use cron since 1 minute minimum time interval. You will need to run a script that will run 60 other scripts with delays from 0 to 59 seconds or one script that will work 60 times.

But at this point, why not just run a single script outside of cron, which is sleeping (1) in a loop?

+2
source

Source: https://habr.com/ru/post/1388491/


All Articles