Does anyone know how to reduce CPU usage of a polling program running in Linux? The program is basically a polling loop that sleeps for a short period if there is no activity in that loop. On my system the select and nanosleep functions have a granularity of ~10ms (I'm assuming this is due to a scheduler of 100Hz tick rate). Is there a way to sleep for around 1ms (precision is not important, but order of magnitude is) without destroying the RTC??

Thanks for any info!

9 Years
Discussion Span
Last Post by dougy83

I have found a solution to my problem, although it isn't obvious given the lack of background info in my previous post - I should have mentioned that the polling is of sockets and serial ports - and thus I can use the poll() function (select() doesn't seem to work with serial ports).

That said, if anyone knows how the nanosleep granularity better than the scheduler clock rate, I'd love to hear how.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.