目的:每秒执行定时任务
环境: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
1
arrow8899 2019-07-28 19:18:16 +08:00
OnUnitActiveSec=1s
https://www.freedesktop.org/software/systemd/man/systemd.timer.html |