Running a script every second

Rich Felker dalias at aerifal.cx
Fri Mar 7 00:04:10 UTC 2014


On Thu, Mar 06, 2014 at 02:34:25PM -0500, Michael Conrad wrote:
> I know this borders on bike-shedding, but if you really want to run
> something exactly 60 times per elapsed minute you need to compare
> calls to clock_gettime(CLOCK_MONOTONIC).  Nothing else will work
> reliably in all cases, and certainly not signals.  (if the system is
> lagged significantly, two signals can be merged into one)

POSIX timers with signal-based delivery can be used reliably for this
purpose too. Realtime signals can be queued, and even if the queue
overflows, the timer_getoverrun() function can tell you how many
overruns there were (so you can compensate).

In principle POSIX timers with thread-based delivery should also work
for this purpose, but due to bugs in glibc, it's not 100% reliable and
expirations may be lost. And if you don't mind using threads, it's
easy to just roll your own approach with clock_gettime and
clock_nanosleep with TIMER_ABSTIME, as you described.

Rich


More information about the busybox mailing list