I saw in usleep man that :
EINVAL
usec is not smaller than 1000000. (On systems where that is considered an error.)
So i wonder if its ok to use usleep in Ubuntu with value greater than 1000000 and if not (or in case that i want to support other platforms ) what is the alternative when i need sleep for 2.2 sec (for example) .
Thank you.
One alternative is to trust the documentation and implement it using a loop just to be safe:
You should also inspect the return value of
usleep(), I omitted that for brevity.In production, you can have fun with Autoconf and friends to detect the proper
USLEEP_MAXat compile-time, and even switch to a plain wrapper if the local system doesn’t have a limit for the argument. Hours of fun can be had.