以上所有方法,放在linux上执行时,会出一个坑,出现多个进程.
因为若遇到延时,超出60秒后,第二个定时任务启动.就会出现多个进程.
解决方法,加文件锁/usr/bin/flock
crontab 最短定义只能到分钟,只能用脚本sleep 来完成
还是说说你的使用场景吧
没找到啊。只能到分钟级别,秒都到不了。
windows机器不方便试,大概这样的
#!/bin/bash
for i in {1..120}
do
usleep 500
RUN_YOUR_TASK&
done
用usleep睡半秒,持续一分钟,结合cron就行了
用watch
watch -n 0.5 date
试试看
由于 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 所以没有亲测,大概就是这么个思路
* * * * * for i in `seq 120`; do awesome_scripts& sleep 0.5; done
由crontab每分钟调度,每次唤起,循环执行120次,间隔0.5秒