Does calling sleep from a shell script prevent device suspend?

Assuming I’m doing something like this in a shell script (busybox or bash):

while sleep 15; do
   do_something()
done

Will the device be able to suspend/sleep while the sleep part is executing?

Will it make a difference whether I use /bin/sleep or shell builtins?

I want so_something to actually not get executed when the device wants to suspend/sleep.

Assuming that’s not possible with shell, are there alternatives/tricks apart from writing something like a custom (libev/event based?) C program?

Assuming that do_something does not prevent sleeping, your device will sleep just fine. note that it will also ignore 15s for wakeup. So, sleep is expected to be longer than you put there. If you want to have better control over it, use keepalive library and do something around it.

3 Likes

Good to know, thank you.

I’m asking as I’m playing around with collectd’s Exec mechanism. Official docs recommend using a shell loop like this, but it will also work as a oneshot script.

So I wondered what would be more efficient, shell sleep or collectd sleeping and re-executing the script each interval.

By the way, thank you for your work with collectd and systemdatascope!

welcome :slight_smile:

as collectd (on Sailfish) already implements suspend/resume support via keepalive, I would suggest to go for single shot. To not impact your battery, look for time intervals of 2.5-5 min or so.

2 Likes