How to make a daemon to be running exactly at given time?

asked 2016-02-17 14:56:43 +0300

Rikudou_Sennin gravatar image

Hello,

I am writing a daemon for Sailfish and I noticed that it behaves slightly different than on standard Linux distribution.

The daemon should run in five minutes intervals starting from the nearest five minutes block. E.g. when it's 42 minutes, it should wait to 45.

I made some functions that count the exact number of seconds to sleep before invoking, but it seems to ignore it and sleeps a lot longer.

It is my log from testing this daemon on computer:

[2016-02-17 13:35:43] Sleeping for 257 seconds

[2016-02-17 13:40:00] would be generated right now

[2016-02-17 13:40:01] would be generated right now

[2016-02-17 13:40:02] would be generated right now

Notice that on computer it runs exactly at 13:40:00 which is the result I want, then it should trigger it every second (it's only for testing purposes). Jolla does this:

[2016-02-17 13:47:11] Sleeping for 169 seconds

[2016-02-17 13:52:47] would be generated right now

[2016-02-17 13:53:10] would be generated right now

[2016-02-17 13:53:11] would be generated right now

Is there any way to solve this?

edit retag flag offensive close delete

Comments

1
1

And then the daemon will be realiable?

Rikudou_Sennin ( 2016-02-17 15:07:11 +0300 )edit

Can you help me please with setting up the timer?

Rikudou_Sennin ( 2016-02-17 15:21:16 +0300 )edit

Haven't messed around with it but you will need a .timer file that will describe when it is activated and a .service file to do what you want it to do.

https://wiki.archlinux.org/index.php/Systemd/Timers

As for reliability i can't comment.

I suspect that your problem has to do with the way jolla puts itself to sleep in order to save battery.

ApB ( 2016-02-17 16:15:22 +0300 )edit
1

@Rikudou_Sennin, check the use of libiphb in cron http://www.swagman.org/juice/vixie-cron-3.0pl1-1.src.rpm

You can use that for the most accurate sleep-timing. (better than systemd timers)

juiceme ( 2016-02-17 22:23:25 +0300 )edit