#include <unistd.h> unsigned int usleep( useconds_t useconds );
The usleep() function suspends a thread for the number of microseconds specified by the of useconds parameter. (Because of processor delays, the thread can be suspended slightly longer than this specified time.)
The usleep() function uses the process's real-time interval timer to indicate when the thread should be resumed.
There is one real-time interval timer for each process. The usleep() function will not interfere with a previous setting of this timer.
None.
0 | The thread slept for the full time specified. |
-1 | sleep() was not successful. The errno variable is set to indicate the error. |
If usleep() is not successful, errno usually indicates the following error. Under some conditions, errno could indicate an error other than that listed here.
A function was passed incorrect argument values, or an operation was attempted on an object and the operation specified is not supported for that type of object.
An argument value is not valid, out of range, or NULL.
The usleep() function is included for its historical usage. The setitimer() function is preferred over this function.
See Code disclaimer information for information pertaining to code examples.
The following example uses the usleep() function to suspend processing for a specified time:
#include <unistd.h> #include <stdio.h> #include <time.h> void timestamp( char *str ) { time_t t; time( &t ); printf( "%s the time is %s\nquot;, str, ctime(&t) ); } int main( int argc, char *argv[] ) { int result = 0; timestamp( quot;before usleep()quot; ); result = usleep( 999999 ); timestamp( quot;after usleep()quot; ); printf( quot;usleep() returned %d\nquot;, result ); return( result ); }
before usleep() the time is Sun Jun 15 17:25:17 1995 after usleep() the time is Sun Jun 15 17:25:18 1995 usleep() returned 0
Top | UNIX-Type APIs | APIs by category |