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.
what's even better than sleep and usleep??
select() of course. Selecting on no file descriptors with NULLs as sets, you can set a timer up to delay as many microseconds as you'd like. In fact, if you man select you'll find that it suggests using that as a nice delay. I don't know of any portability issues with it, but ymmv.
yeah, but hasn't usleep been deprecated because it has unspecified interactions with sigalarm and friends? Also, usleep has some portability issues with BSD/SysV/glibc etc... whereas select() doesn't
Also, exposure to select() isn't [edit] a bad thing [/edit] in case that helps him with his project (IE: He was sleeping because some other process was writing to a file that he wanted to read from so he guessed that it was done writing after X seconds, etc...)
Originally posted by orgcandman yeah, but hasn't usleep been deprecated because it has unspecified interactions with sigalarm and friends? Also, usleep has some portability issues with BSD/SysV/glibc etc... whereas select() doesn't
I didn't know that. And your right. The man page says:
"This function is obsolete. Use nanosleep(2) or setitimer(2) instead."
(note however that it does not recommend select() instead of usleep() )
Quote:
Originally posted by orgcandman Also, exposure to select() isn't a bad thing in case that helps him with his project
True. One could learn much about programming finding out how select() works, as it is quite complex.
Quote:
Originally posted by orgcandman (IE: He was sleeping because some other process was writing to a file that he wanted to read from so he guessed that it was done writing after X seconds, etc...)
Well, yes, but that is either just your guess, or you know more about his specific project than what's in this thread.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.