Hello,

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!
-Doug.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.