1nanosleep(3C) Standard C Library Functions nanosleep(3C)
2
3
4
6 nanosleep - high resolution sleep
7
9 #include <time.h>
10
11 int nanosleep(const struct timespec *rqtp,
12 struct timespec *rmtp);
13
14
16 The nanosleep() function causes the current thread to be suspended
17 from execution until either the time interval specified by the rqtp
18 argument has elapsed or a signal is delivered to the calling thread and
19 its action is to invoke a signal-catching function or to terminate the
20 process. The suspension time may be longer than requested because the
21 argument value is rounded up to an integer multiple of the sleep reso‐
22 lution or because of the scheduling of other activity by the system.
23 But, except for the case of being interrupted by a signal, the suspen‐
24 sion time will not be less than the time specified by rqtp, as measured
25 by the system clock, CLOCK_REALTIME.
26
27
28 The use of the nanosleep() function has no effect on the action or
29 blockage of any signal.
30
32 If the nanosleep() function returns because the requested time has
33 elapsed, its return value is 0.
34
35
36 If the nanosleep() function returns because it has been interrupted by
37 a signal, the function returns a value of −1 and sets errno to indicate
38 the interruption. If the rmtp argument is non-NULL, the timespec struc‐
39 ture referenced by it is updated to contain the amount of time remain‐
40 ing in the interval (the requested time minus the time actually slept).
41 If the rmtp argument is NULL, the remaining time is not returned.
42
43
44 If nanosleep() fails, it returns −1 and sets errno to indicate the
45 error.
46
48 The nanosleep() function will fail if:
49
50 EINTR The nanosleep() function was interrupted by a signal.
51
52
53 EINVAL The rqtp argument specified a nanosecond value less than zero
54 or greater than or equal to 1000 million.
55
56
57 ENOSYS The nanosleep() function is not supported by this implementa‐
58 tion.
59
60
62 See attributes(5) for descriptions of the following attributes:
63
64
65
66
67 ┌─────────────────────────────┬─────────────────────────────┐
68 │ATTRIBUTE TYPE │ATTRIBUTE VALUE │
69 ├─────────────────────────────┼─────────────────────────────┤
70 │Interface Stability │Committed │
71 ├─────────────────────────────┼─────────────────────────────┤
72 │MT-Level │MT-Safe │
73 ├─────────────────────────────┼─────────────────────────────┤
74 │Standard │See standards(5). │
75 └─────────────────────────────┴─────────────────────────────┘
76
78 sleep(3C), time.h(3HEAD), attributes(5), standards(5)
79
80
81
82SunOS 5.11 5 Feb 2008 nanosleep(3C)