1 .\" Copyright (c) 2008, Linux Foundation, written by Michael Kerrisk
2 .\" <mtk.manpages@gmail.com>
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" Japanese Version Copyright (c) 2008 Akihiro MOTOKI
25 .\" all rights reserved.
26 .\" Translated 2008-08-21, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.04
28 .TH CLOCK_NANOSLEEP 2 2008-07-09 "Linux" "Linux Programmer's Manual"
31 .\"O clock_nanosleep \- high-resolution sleep with specifiable clock
32 clock_nanosleep \- »ØÄꤷ¤¿¥¯¥í¥Ã¥¯¤Ç¤Î¹âÀºÅ٤ʼ¹ÔÄä»ß (sleep)
38 .BI "int clock_nanosleep(clockid_t " clock_id ", int " flags ,
39 .BI " const struct timespec *" request ,
40 .BI " struct timespec *" remain );
43 .\"O Link with \fI\-lrt\fP.
44 \fI\-lrt\fP ¤Ç¥ê¥ó¥¯¤¹¤ë¡£
47 .\"O Feature Test Macro Requirements for glibc (see
48 .\"O .BR feature_test_macros (7)):
49 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
50 .RB ( feature_test_macros (7)
54 .BR clock_nanosleep ():
55 _XOPEN_SOURCE\ >=\ 600
59 .\"O .BR nanosleep (2),
60 .\"O .BR clock_nanosleep ()
61 .\"O allows the caller to sleep for an interval specified
62 .\"O with nanosecond precision.
63 .\"O It differs in allowing the caller to select the clock against
64 .\"O which the sleep interval is to be measured,
65 .\"O and in allowing the sleep interval to be specified as
66 .\"O either an absolute or a relative value.
67 .BR clock_nanosleep ()
70 ƱÍÍ¡¢¥Ê¥ÎÉäÎÀºÅ٤ǻØÄꤵ¤ì¤¿´ü´Ö¤À¤±¸Æ¤Ó½Ð¤·¤¿¥¹¥ì¥Ã¥É¤Î¼Â¹Ô¤ò
71 Ää»ß¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£
73 ¤È°ã¤¦¤Î¤Ï¡¢¸Æ¤Ó½Ð¤·Â¦¤¬Ää»ß´ü´Ö¤ò¤É¤Î¥¯¥í¥Ã¥¯¤ËÂФ·¤Æ·×¬¤¹¤ë¤Î¤«¤òÁªÂò
74 ¤Ç¤¤ëÅÀ¤È¡¢Ää»ß´ü´Ö¤òÀäÂÐÃͤǤâÁêÂÐÃͤǤâ»ØÄê¤Ç¤¤ëÅÀ¤Ç¤¢¤ë¡£
76 .\"O The time values passed to and returned by this call are specified using
78 .\"O structures, defined as follows:
79 ¤³¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤ËÅϤ·¤¿¤ê¡¢¤³¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤¬ÊÖ¤·¤¿¤ê¤¹¤ë»þ´Ö¤ÎÃͤÏ
81 ¹½Â¤ÂΤò»È¤Ã¤Æ»ØÄꤵ¤ì¤ë¡£¤³¤Î¹½Â¤ÂΤÎÄêµÁ¤Ï°Ê²¼¤ÎÄ̤ê¤Ç¤¢¤ë¡£
86 time_t tv_sec; /* seconds */
87 long tv_nsec; /* nanoseconds [0 .. 999999999] */
94 .\"O argument specifies the clock against which the sleep interval
95 .\"O is to be measured.
96 .\"O This argument can have one of the following values:
98 °ú¤¿ô¤Ç¡¢Ää»ß´ü´Ö¤ò¤É¤Î¥¯¥í¥Ã¥¯¤ËÂФ·¤Æ·×¬¤¹¤ë¤«¤ò»ØÄꤹ¤ë¡£
99 ¤³¤Î°ú¤¿ô¤Ë¤Ï°Ê²¼¤ÎÃͤΤ¤¤º¤ì¤«°ì¤Ä¤ò»ØÄê¤Ç¤¤ë¡£
102 .\"O A settable system-wide real-time clock.
103 ¥·¥¹¥Æ¥àÁ´ÂΤǻȤï¤ì¤ë¼Â»þ´Ö¥¯¥í¥Ã¥¯¡£
104 ¤³¤Î¥¯¥í¥Ã¥¯¤ÏÊѹ¹²Äǽ¤Ç¤¢¤ë¡£
107 .\"O A nonsettable, monotonically increasing clock that measures time
108 .\"O since some unspecified point in the past that does not change after
110 .\"O .\" On Linux this clock measures time since boot.
111 ²áµî¤Î¤¢¤ë»þÅÀ¤«¤é¤Î»þ´Ö¤ò·×¬¤¹¤ë¡¢Ã±Ä´Áý²Ã¤Î¥¯¥í¥Ã¥¯¡£
112 µ¯ÅÀ¤È¤Ê¤ë»þÅÀ¤Ï¥·¥¹¥Æ¥àµ¯Æ°¸å¤Ë¤ÏÊѹ¹¤µ¤ì¤Ê¤¤¡£
113 ¤³¤Î¥¯¥í¥Ã¥¯¤ÏÊѹ¹¤¹¤ë¤³¤È¤¬¤Ç¤¤Ê¤¤¡£
114 .\" Linux ¤Ç¤Ï¡¢¤³¤Î¥¯¥í¥Ã¥¯¤Ïµ¯Æ°¤«¤é¤Î»þ´Ö¤ò·×¬¤¹¤ë¡£
116 .BR CLOCK_PROCESS_CPUTIME_ID
117 .\"O A settable per-process clock that measures CPU time consumed
118 .\"O by all threads in the process.
119 ¤½¤Î¥×¥í¥»¥¹¤ÎÁ´¥¹¥ì¥Ã¥É¤Ç¾ÃÈñ¤µ¤ì¤ë CPU »þ´Ö¤ò·×¬¤¹¤ë¥×¥í¥»¥¹Ã±°Ì¤Î
120 ¥¯¥í¥Ã¥¯¡£¤³¤Î¥¯¥í¥Ã¥¯¤ÏÀßÄê²Äǽ¤Ç¤¢¤ë¡£
121 .\" There is some trickery between glibc and the kernel
122 .\" to deal with the CLOCK_PROCESS_CPUTIME_ID case.
125 .\"O .BR clock_getres (2)
126 .\"O for further details on these clocks.
127 ¤³¤ì¤é¤Î¥¯¥í¥Ã¥¯¤Î¾ÜºÙ¤Ë¤Ä¤¤¤Æ¤Ï
133 .\"O is 0, then the value specified in
135 .\"O is interpreted as an interval relative to the current
136 .\"O value of the clock specified by
143 ¤Ç»ØÄꤵ¤ì¤¿¥¯¥í¥Ã¥¯¤Î¸½ºß¤ÎÃͤ«¤é¤ÎÁêÂÐŪ¤Ê´ü´Ö¤È²ò¼á¤µ¤ì¤ë¡£
148 .\"O .BR TIMER_ABSTIME ,
151 .\"O is interpreted as an absolute time as measured by the clock,
155 .\"O is less than or equal to the current value of the clock,
157 .\"O .BR clock_nanosleep ()
158 .\"O returns immediately without suspending the calling thread.
164 ¤Ï»ØÄꤵ¤ì¤¿¥¯¥í¥Ã¥¯¤Ç·×¬¤µ¤ì¤ëÀäÂлþ¹ï¤È²ò¼á¤µ¤ì¤ë¡£
166 ¤¬»ØÄꤵ¤ì¤¿¥¯¥í¥Ã¥¯¤Î¸½ºß¤ÎÃͰʲ¼¤Î¾ì¹ç¡¢
167 .BR clock_nanosleep ()
168 ¤Ï¡¢¸Æ¤Ó½Ð¤·¤¿¥¹¥ì¥Ã¥É¤ÎÄä»ß¤ò¹Ô¤ï¤º¡¢¤¹¤°¤ËÊ֤롣
170 .\"O .BR clock_nanosleep ()
171 .\"O suspends the execution of the calling thread
172 .\"O until either at least the time specified by
175 .\"O or a signal is delivered that causes a signal handler to be called or
176 .\"O that terminates the process.
177 .BR clock_nanosleep ()
180 ¤Ç»ØÄꤵ¤ì¤¿»þ´Ö¤¬·Ð²á¤¹¤ë¤Þ¤Ç¡¢¸Æ¤Ó½Ð¤·¤¿¥¹¥ì¥Ã¥É¤Î¼Â¹Ô¤òÄä»ß¤¹¤ë¡£
181 ¥·¥°¥Ê¥ë¥Ï¥ó¥É¥é¤¬¸Æ¤Ó½Ð¤µ¤ì¤¿¤ê¡¢¤½¤Î¥×¥í¥»¥¹¤ò½ªÎ»¤µ¤»¤ë¤è¤¦¤Ê
182 ¥·¥°¥Ê¥ë¤¬ÇÛÁ÷¤µ¤ì¤¿¤ê¤·¤¿¾ì¹ç¤Ë¤â¡¢¥¹¥ì¥Ã¥É¤Î¼Â¹ÔÄä»ß¤Ï½ªÎ»¤¹¤ë¡£
184 .\"O If the call is interrupted by a signal handler,
185 .\"O .BR clock_nanosleep ()
186 .\"O returns \-1, and sets
192 .\"O is not NULL, and
195 .\"O .BR TIMER_ABSTIME ,
196 .\"O it returns the remaining unslept time in
198 .\"O This value can then be used to call
199 .\"O .BR clock_nanosleep ()
200 .\"O again and complete a (relative) sleep.
201 ¸Æ¤Ó½Ð¤·¤¬¥·¥°¥Ê¥ë¥Ï¥ó¥É¥é¤Ë¤è¤Ã¤Æ³ä¤ê¹þ¤Þ¤ì¤¿¾ì¹ç¡¢
202 .BR clock_nanosleep ()
207 ¤òÀßÄꤹ¤ë¡£¤½¤ì¤Ë²Ã¤¨¤Æ¡¢
215 ¤Ë»Ä¤ê¤ÎÄä»ß»þ´Ö¤¬ÊÖ¤µ¤ì¤ë¡£
217 .BR clock_nanosleep ()
218 ¤òºÆÅٸƤӽФ¹¤³¤È¤Ç¡¢(ÁêÂÐŪ¤Ê´ü´Ö¤Î) Ää»ß¤ò´°Î»¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£
219 .\"O .SH "RETURN VALUE"
221 .\"O On successfully sleeping for the requested interval,
222 .\"O .BR clock_nanosleep ()
224 .\"O If the call is interrupted by a signal handler or encounters an error,
225 .\"O then it returns a positive error number.
226 Í׵ᤵ¤ì¤¿´ü´Ö¤ÎÄä»ß¤ËÀ®¸ù¤¹¤ë¤È¡¢
227 .BR clock_nanosleep ()
229 ¥·¥°¥Ê¥ë¥Ï¥ó¥É¥é¤Ç³ä¤ê¹þ¤Þ¤ì¤¿¤ê¡¢¥¨¥é¡¼¤¬È¯À¸¤·¤¿¤ê¤·¤¿¾ì¹ç¡¢
230 Àµ¤Î¥¨¥é¡¼ÈÖ¹æ¤òÊÖ¤¹¡£
238 .\"O specified an invalid address.
242 ¤Ë̵¸ú¤Ê¥¢¥É¥ì¥¹¤¬»ØÄꤵ¤ì¤¿¡£
245 .\"O The sleep was interrupted by a signal handler.
246 Ää»ß¤¬¥·¥°¥Ê¥ë¥Ï¥ó¥É¥é¤Ë¤è¤ê³ä¤ê¹þ¤Þ¤ì¤¿¡£
249 .\"O The value in the
251 .\"O field was not in the range 0 to 999999999 or
255 ¥Õ¥£¡¼¥ë¥É¤ÎÃͤ¬ 0 ¤«¤é 999999999 ¤ÎÈϰϤǤʤ¤¤«¡¢
262 .\"O .RB ( CLOCK_THREAD_CPUTIME_ID
263 .\"O is not a permitted value for
267 .RB ( CLOCK_THREAD_CPUTIME_ID
270 ¤È¤·¤Æ͸ú¤ÊÃͤǤϤʤ¤)¡£
274 .\"O .BR clock_nanosleep ()
275 .\"O system call first appeared in Linux 2.6.
276 .\"O Support is available in glibc since version 2.1.
277 .BR clock_nanosleep ()
278 ¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï Linux 2.6 ¤Ç½é¤á¤ÆÅо줷¤¿¡£
279 glibc ¤Ç¤Ï¥Ð¡¼¥¸¥ç¥ó 2.1 °Ê¹ß¤Ç¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¡£
280 .\"O .SH "CONFORMING TO"
285 .\"O If the interval specified in
287 .\"O is not an exact multiple of the granularity underlying clock (see
289 .\"O then the interval will be rounded up to the next multiple.
290 .\"O Furthermore, after the sleep completes, there may still be a delay before
291 .\"O the CPU becomes free to once again execute the calling thread.
293 ¤Ç»ØÄꤵ¤ì¤¿Ää»ß´ü´Ö¤¬¡¢»þ´Ö¤Î·×¬¤Ë»ÈÍѤµ¤ì¤ë¥¯¥í¥Ã¥¯
295 »²¾È) ¤ÎÀºÅÙ¤ÎÇÜ¿ô¤Á¤ç¤¦¤É¤Ç¤Ê¤¤¾ì¹ç¡¢Ää»ß´ü´Ö¤Ï°ìÈֶᤤ¼¡¤ÎÇÜ¿ô¤Ë
296 ÀÚ¤ê¾å¤²¤é¤ì¤ë¡£¤µ¤é¤Ë¡¢Ää»ß¤¬´°Î»¤·¤¿¸å¤Ë¡¢CPU ¤¬¸Æ¤Ó½Ð¤·¤¿¥¹¥ì¥Ã¥É¤ò
297 ¤â¤¦°ìÅټ¹ԤǤ¤ë¤è¤¦¤Ë¤Ê¤ë¤Þ¤Ç¤Ë¤Ï¡¢Ãٱ䤬Æþ¤ë²ÄǽÀ¤¬¤¢¤ë¡£
299 .\"O Using an absolute timer is useful for preventing
300 .\"O timer drift problems of the type described in
301 .\"O .BR nanosleep (2).
302 .\"O (Such problems are exacerbated in programs that try to restart
303 .\"O a relative sleep that is repeatedly interrupted by signals.)
304 ÀäÂÐÃÍ»ØÄê¤Î¥¿¥¤¥Þ¤ò»È¤¦¤Î¤Ï¡¢
306 ¤Ë½ñ¤«¤ì¤Æ¤¤¤ëÎà¤Î¥¿¥¤¥Þ¤Î¤º¤ì¤ÎÌäÂê¤òËɻߤ¹¤ë¤Î¤ËÌòΩ¤Ä
307 (¤³¤Î¼ï¤ÎÌäÂê¤Ï¡¢¥·¥°¥Ê¥ë¤Ë³ä¤ê¹þ¤Þ¤ì¤¿ºÝ¤ËÁêÂлØÄê¤ÎÄä»ß¤ò
308 ·«¤êÊÖ¤·ºÆ³«¤·¤è¤¦¤È¤¹¤ë¥×¥í¥°¥é¥à¤Ç¤Ï¡¢¤«¤¨¤Ã¤Æ°²½¤¹¤ë)¡£
309 .\"O To perform a relative sleep that avoids these problems, call
310 .\"O .BR clock_gettime (2)
311 .\"O for the desired clock,
312 .\"O add the desired interval to the returned time value,
314 .\"O .BR clock_nanosleep ()
316 .\"O .B TIMER_ABSTIME
318 ¤³¤ì¤é¤ÎÌäÂê¤ò²óÈò¤·¤ÆÁêÂлØÄê¤ÎÄä»ß¤ò¼Â¹Ô¤¹¤ë¤Ë¤Ï¡¢
320 .BR clock_gettime (2)
321 ¤ò¸Æ¤Ó½Ð¤·¡¢¤½¤ÎÊÖ¤êÃͤλþ¹ïÃͤ˴õ˾¤¹¤ë´ü´Ö¤ò²Ã»»¤·¤Æ¤«¤é¡¢
324 .BR clock_nanosleep ()
327 .\"O .BR clock_nanosleep ()
328 .\"O is never restarted after being interrupted by a signal handler,
329 .\"O regardless of the use of the
330 .\"O .BR sigaction (2)
336 ¥Õ¥é¥°¤¬»ØÄꤵ¤ì¤Æ¤¤¤ë¤«¤Ë´Ø¤ï¤é¤º¡¢
337 ¥·¥°¥Ê¥ë¥Ï¥ó¥É¥é¤Ë¤è¤ê³ä¤ê¹þ¤Þ¤ì¤¿¸å¤Ë
338 .BR clock_nanosleep ()
339 ¤¬ºÆ³«¤µ¤ì¤ë¤³¤È¤Ï·è¤·¤Æ¤Ê¤¤¡£
343 .\"O argument is unused, and unnecessary, when
346 .\"O .BR TIMER_ABSTIME .
347 .\"O (An absolute sleep can be restarted using the same
355 °ú¤¿ô¤Ï»ÈÍѤµ¤ì¤º¡¢ÉÔÍפǤ¢¤ë
356 (ÀäÂÐÃͤǤÎÄä»ß¤Ç¤Ï¡¢Æ±¤¸
358 °ú¤¿ô¤ò»È¤Ã¤ÆºÆÅٸƤӽФ¹¤³¤È¤¬¤Ç¤¤ë)¡£
360 .\"O POSIX.1 specifies that
361 .\"O .BR clock_nanosleep ()
362 .\"O has no effect on signals dispositions or the signal mask.
364 .BR clock_nanosleep ()
365 ¤Ï¥·¥°¥Ê¥ë¤Î½èÍýÊýË¡¤ä¥·¥°¥Ê¥ë¥Þ¥¹¥¯¤Ë±Æ¶Á¤òÍ¿¤¨¤Ê¤¤¡¢¤È¤µ¤ì¤Æ¤¤¤ë¡£
367 .\"O POSIX.1 specifies that after changing the value of the
368 .\"O .B CLOCK_REALTIME
370 .\"O .BR clock_settime (2),
371 .\"O the new clock value shall be used to determine the time
372 .\"O at which a thread blocked on an absolute
373 .\"O .BR clock_nanosleep ()
375 .\"O if the new clock value falls past the end of the sleep interval, then the
376 .\"O .BR clock_nanosleep ()
377 .\"O call will return immediately.
379 .BR clock_settime (2)
382 ¥¯¥í¥Ã¥¯¤ÎÃͤòÊѹ¹¤·¤¿¸å¤Ï¡¢ÀäÂÐÃÍ»ØÄê¤Î
383 .BR clock_nanosleep ()
384 ¤ÇÄä»ß¤·¤Æ¤¤¤ë¥¹¥ì¥Ã¥É¤òµ¯Æ°¤µ¤»¤ë»þ¹ï¤ÎȽÄê¤Ï¡¢
385 ¿·¤·¤¤¥¯¥í¥Ã¥¯Ãͤò»È¤Ã¤Æ¹Ô¤ï¤ì¤ë¡¢¤È¤µ¤ì¤Æ¤¤¤ë¡£
386 ¿·¤·¤¤¥¯¥í¥Ã¥¯Ãͤˤª¤¤¤ÆÄä»ß´ü´Ö¤Î½ªÎ»»þ¹ï¤¬²áµî¤Ë¤Ê¤Ã¤Æ¤·¤Þ¤Ã¤¿¾ì¹ç¤Ë¤Ï¡¢
387 .BR clock_nanosleep ()
388 ¤Ï¤¹¤°¤ËÊ֤뤳¤È¤Ë¤Ê¤ë¡£
390 .\"O POSIX.1 specifies that
391 .\"O changing the value of the
392 .\"O .B CLOCK_REALTIME
394 .\"O .BR clock_settime (2)
395 .\"O shall have no effect on a thread that is blocked on a relative
396 .\"O .BR clock_nanosleep ().
398 .BR clock_settime (2)
401 ¥¯¥í¥Ã¥¯¤ÎÃͤòÊѹ¹¤·¤Æ¤â¡¢ÁêÂÐÃÍ»ØÄê¤Î
402 .BR clock_nanosleep ()
403 ¤ÇÄä»ß¤·¤Æ¤¤¤ë¥¹¥ì¥Ã¥É¤Ë¤Ï±Æ¶Á¤òÍ¿¤¨¤Ê¤¤¡¢¤È¤µ¤ì¤Æ¤¤¤ë¡£
406 .BR clock_getres (2),
408 .BR timer_create (2),