1USLEEP(P) POSIX Programmer's Manual USLEEP(P)
2
3
4
6 usleep - suspend execution for an interval
7
9 #include <unistd.h>
10
11 int usleep(useconds_t useconds);
12
13
15 The usleep() function shall cause the calling thread to be suspended
16 from execution until either the number of realtime microseconds speci‐
17 fied by the argument useconds has elapsed or a signal is delivered to
18 the calling thread and its action is to invoke a signal-catching func‐
19 tion or to terminate the process. The suspension time may be longer
20 than requested due to the scheduling of other activity by the system.
21
22 The useconds argument shall be less than one million. If the value of
23 useconds is 0, then the call has no effect.
24
25 If a SIGALRM signal is generated for the calling process during execu‐
26 tion of usleep() and if the SIGALRM signal is being ignored or blocked
27 from delivery, it is unspecified whether usleep() returns when the
28 SIGALRM signal is scheduled. If the signal is being blocked, it is also
29 unspecified whether it remains pending after usleep() returns or it is
30 discarded.
31
32 If a SIGALRM signal is generated for the calling process during execu‐
33 tion of usleep(), except as a result of a prior call to alarm(), and if
34 the SIGALRM signal is not being ignored or blocked from delivery, it is
35 unspecified whether that signal has any effect other than causing
36 usleep() to return.
37
38 If a signal-catching function interrupts usleep() and examines or
39 changes either the time a SIGALRM is scheduled to be generated, the
40 action associated with the SIGALRM signal, or whether the SIGALRM sig‐
41 nal is blocked from delivery, the results are unspecified.
42
43 If a signal-catching function interrupts usleep() and calls sig‐
44 longjmp() or longjmp() to restore an environment saved prior to the
45 usleep() call, the action associated with the SIGALRM signal and the
46 time at which a SIGALRM signal is scheduled to be generated are unspec‐
47 ified. It is also unspecified whether the SIGALRM signal is blocked,
48 unless the process' signal mask is restored as part of the environment.
49
50 Implementations may place limitations on the granularity of timer val‐
51 ues. For each interval timer, if the requested timer value requires a
52 finer granularity than the implementation supports, the actual timer
53 value shall be rounded up to the next supported value.
54
55 Interactions between usleep() and any of the following are unspecified:
56
57
58 nanosleep()
59 setitimer()
60 timer_create()
61 timer_delete()
62 timer_getoverrun()
63 timer_gettime()
64 timer_settime()
65 ualarm()
66 sleep()
67
69 Upon successful completion, usleep() shall return 0; otherwise, it
70 shall return -1 and set errno to indicate the error.
71
73 The usleep() function may fail if:
74
75 EINVAL The time interval specified one million or more microseconds.
76
77
78 The following sections are informative.
79
81 None.
82
84 Applications are recommended to use nanosleep() if the Timers option is
85 supported, or setitimer(), timer_create(), timer_delete(),
86 timer_getoverrun(), timer_gettime(), or timer_settime() instead of this
87 function.
88
90 None.
91
93 None.
94
96 alarm() , getitimer() , nanosleep() , sigaction() , sleep() ,
97 timer_create() , timer_delete() , timer_getoverrun() , the Base Defini‐
98 tions volume of IEEE Std 1003.1-2001, <unistd.h>
99
101 Portions of this text are reprinted and reproduced in electronic form
102 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
103 -- Portable Operating System Interface (POSIX), The Open Group Base
104 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
105 Electrical and Electronics Engineers, Inc and The Open Group. In the
106 event of any discrepancy between this version and the original IEEE and
107 The Open Group Standard, the original IEEE and The Open Group Standard
108 is the referee document. The original Standard can be obtained online
109 at http://www.opengroup.org/unix/online.html .
110
111
112
113IEEE/The Open Group 2003 USLEEP(P)