ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
be careful in that usleep() and nanosleep() may always sleep for at least 1 or 10 milliseconds regardless of how long you ask to sleep. If you need less than this, the nanosleep manpage says some stuff about using sched_setscheduler to make it so you will spin instead of sleep.
Originally posted by aluser be careful in that usleep() and nanosleep() may always sleep for at least 1 or 10 milliseconds regardless of how long you ask to sleep. If you need less than this, the nanosleep manpage says some stuff about using sched_setscheduler to make it so you will spin instead of sleep.
aluser:
thanks for clearing that up, i didn't know that
I am 99% sure select will suffer the same problem with regards to accuracy. If the process yields processor time it may sleep for as long as 1/HZ seconds and there's not much to be done about it. The only way to wait for shorter periods is to spin.
HZ is 100 on x86 with 2.4.x and before, and 1000 on x86 with 2.6.x
To use select as a sleep, just select(1, NULL, NULL, NULL, &timeout) -- no need to create any file descriptor.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.