[EXTERNAL] Re: How efficient is 'sleep'?
Lavrentiev, Anton (NIH/NLM/NCBI) [C]
lavr@ncbi.nlm.nih.gov
Sat Dec 16 17:36:51 GMT 2023
> the process isn't allocated any CPU time until the timer expires.
Almost so. But the "sleep" functions are interruptible, so if a process (the "sleep" command)
is somehow signaled, it will wake up prematurely, and will have to either put itself back to
sleep (for the remaining unslept time) or terminate, whatever the implementation is. So in the
former case, there is some CPU still consumed (and that would depend on how often the signal
arrives), and in the former case, the actual slept time can be quite inaccurate (from what you
think it should have been).
Signaling with scripts can be quite tricky as the signal can propagate to the entire process
group, rather than a single process (depending on which process the signal was sent to).
Using cron (as others suggested) gives you a time accuracy up to a second (give or take), but
then again it depends on the load of the system, and may drift rather significantly.
My $.02,
Anton Lavrentiev
Contractor NIH/NLM/NCBI
More information about the Cygwin
mailing list