目的:每秒执行定时任务
环境: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
执行结果:
[[email protected] 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 C