Heim > Fragen und Antworten > Hauptteil
PHP中文网2017-04-17 12:08:47
* * * * * for i in `seq 120`; do awesome_scripts& sleep 0.5; done
由crontab每分钟调度,每次唤起,循环执行120次,间隔0.5秒
黄舟2017-04-17 12:08:47
由于 crontab
最小单位是分钟,只能自己写程序执行了。给个 shell + python 的例子:
while true ; do ./your-script & ; python -c "import time;time.sleep(0.5)"; done
或者 python + shell:
import time
from subprocess import call
while(True):
call(["./your-script"])
time.sleep(0.5)
没有 linux 所以没有亲测,大概就是这么个思路
迷茫2017-04-17 12:08:47
windows机器不方便试,大概这样的
#!/bin/bash
for i in {1..120}
do
usleep 500
RUN_YOUR_TASK&
done
用usleep睡半秒,持续一分钟,结合cron就行了
巴扎黑2017-04-17 12:08:47
以上所有方法,放在linux上执行时,会出一个坑,出现多个进程.
因为若遇到延时,超出60秒后,第二个定时任务启动.就会出现多个进程.
解决方法,加文件锁/usr/bin/flock