目的:每秒执行定时任务
环境:CentOS
使用绝对时间参数 OnCalendar 来设定每秒执行就会出现停顿 6,7 秒的情况。看下面执行结果
如果是每 2 秒执行就是正常的。
service:
[Unit]
Description=startup Matlab model
[Service]
ExecStart=echo `date` >> /tmp/timer.log
timer:
[Unit]
Description=Runs matlab script every time
[Timer]
OnCalendar=*:*:0/1
Unit=test.service
Persistent=yes
AccuracySec=1us
[Install]
WantedBy=multi-user.target
执行结果:
[root@izj6cb0qckkiraesjuawcnz system]# tail -f /tmp/timer.log
Sun Jul 28 18:49:34 CST 2019
Sun Jul 28 18:49:35 CST 2019
Sun Jul 28 18:49:36 CST 2019
Sun Jul 28 18:49:37 CST 2019
Sun Jul 28 18:49:38 CST 2019
Sun Jul 28 18:49:45 CST 2019
Sun Jul 28 18:49:46 CST 2019
Sun Jul 28 18:49:47 CST 2019
Sun Jul 28 18:49:48 CST 2019
Sun Jul 28 18:49:49 CST 2019
Sun Jul 28 18:49:55 CST 2019
Sun Jul 28 18:49:56 CST 2019
Sun Jul 28 18:49:57 CST 2019
Sun Jul 28 18:49:58 CST 2019
Sun Jul 28 18:49:59 CST 2019
Sun Jul 28 18:50:06 CST 2019
Sun Jul 28 18:50:07 CST 2019
Sun Jul 28 18:50:08 CST 2019
Sun Jul 28 18:50:09 CST 2019
Sun Jul 28 18:50:10 CST 2019
Sun Jul 28 18:50:16 CST 2019
Sun Jul 28 18:50:17 CST 2019
Sun Jul 28 18:50:18 CST 2019
Sun Jul 28 18:50:19 CST 2019
Sun Jul 28 18:50:20 CST 2019
Sun Jul 28 18:50:27 CST 2019
Sun Jul 28 18:50:28 CST 2019
Sun Jul 28 18:50:29 CST 2019
Sun Jul 28 18:50:30 CST 2019
Sun Jul 28 18:50:31 CST 2019
Sun Jul 28 18:50:37 CST 2019
Sun Jul 28 18:50:38 CST 2019
Sun Jul 28 18:50:39 CST 2019
Sun Jul 28 18:50:40 CST 2019
Sun Jul 28 18:50:41 CST 2019
Sun Jul 28 18:50:48 CST 2019
Sun Jul 28 18:50:49 CST 2019
Sun Jul 28 18:50:50 CST 2019
Sun Jul 28 18:50:51 CST 2019
Sun Jul 28 18:50:52 CST 2019
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.