PHP中文网2017-04-17 12:08:47
* * * * * for i in `seq 120`; do awesome_scripts& sleep 0.5; done
Scheduled by crontab every minute, each time it is invoked, the loop is executed 120 times with an interval of 0.5 seconds
黄舟2017-04-17 12:08:47
Since crontab
the minimum unit is minutes, you can only write your own program to execute it. Give an example of shell + python:
while true ; do ./your-script & ; python -c "import time;time.sleep(0.5)"; done
or python + shell:
import time
from subprocess import call
while(True):
call(["./your-script"])
time.sleep(0.5)
I don’t have linux, so I haven’t tested it myself. That’s probably the idea
迷茫2017-04-17 12:08:47
It’s not convenient to test on a Windows machine, maybe something like this
#!/bin/bash
for i in {1..120}
do
usleep 500
RUN_YOUR_TASK&
done
Use usleep to sleep for half a second for one minute, just combine it with cron
黄舟2017-04-17 12:08:47
The shortest definition of crontab can only be up to minutes, which can only be completed with the script sleep
巴扎黑2017-04-17 12:08:47
When all the above methods are executed on Linux, a pit will appear and multiple processes will appear.
Because if there is a delay, after more than 60 seconds, the second scheduled task will start. Multiple processes will appear. process.
The solution is to add file lock /usr/bin/flock