1 .\" Copyright (C) 2008 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" This program is free software; you can redistribute it and/or modify
4 .\" it under the terms of the GNU General Public License as published by
5 .\" the Free Software Foundation; either version 2 of the License, or
6 .\" (at your option) any later version.
8 .\" This program is distributed in the hope that it will be useful,
9 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
10 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 .\" GNU General Public License for more details.
13 .\" You should have received a copy of the GNU General Public License
14 .\" along with this program; if not, write to the Free Software
15 .\" Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18 .\" Japanese Version Copyright (c) 2008 Akihiro MOTOKI
19 .\" all rights reserved.
20 .\" Translated 2008-11-19, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.13
21 .\" Updated 2009-04-24, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP 3.20
23 .TH TIMERFD_CREATE 2 2009-03-10 Linux "Linux Programmer's Manual"
25 timerfd_create, timerfd_settime, timerfd_gettime \-
26 ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿·Ðͳ¤ÇÄÌÃΤ¹¤ë¥¿¥¤¥Þ¡¼
29 .B #include <sys/timerfd.h>
31 .BI "int timerfd_create(int " clockid ", int " flags );
33 .BI "int timerfd_settime(int " fd ", int " flags ,
34 .BI " const struct itimerspec *" new_value ,
35 .BI " struct itimerspec *" old_value );
37 .BI "int timerfd_gettime(int " fd ", struct itimerspec *" curr_value );
40 ¤³¤ì¤é¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï¡¢ËþλÄÌÃΤò¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿·Ðͳ¤ÇÇÛÁ÷¤¹¤ë
41 ¥¿¥¤¥Þ¡¼¤ÎÀ¸À®¤ÈÁàºî¤ò¹Ô¤¦¡£
46 ¤òÍѤ¤¤ëÊýË¡¤ÎÂå¤ï¤ê¤È¤Ê¤ë¤â¤Î¤Ç¤¢¤ê¡¢¤³¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ò
50 ¤Ç´Æ»ë¤Ç¤¤ë¤È¤¤¤¦ÍøÅÀ¤¬¤¢¤ë¡£
52 ¤³¤ì¤é¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤ò»È¤¦¤Î¤Ï¡¢¤½¤ì¤¾¤ì
54 .BR timer_settime (2),
57 .RB ( timer_getoverrun (2)
58 ¤ËÂбþ¤¹¤ë¤â¤Î¤Ï¤Ê¤¯¡¢°Ê²¼¤ÇÀâÌÀ¤¹¤ë¤è¤¦¤Ë
65 ¤Ï¿·µ¬¤Î¥¿¥¤¥Þ¡¼¥ª¥Ö¥¸¥§¥¯¥È¤òÀ¸À®¤·¡¢¤½¤Î¥¿¥¤¥Þ¡¼¤ò»²¾È¤¹¤ë¥Õ¥¡¥¤¥ë
66 ¥Ç¥£¥¹¥¯¥ê¥×¥¿¤òÊÖ¤¹¡£
68 °ú¤¿ô¤Ï¡¢¥¿¥¤¥Þ¡¼¤Î¿ÊĽ¤ò´ÉÍý¤¹¤ë¤¿¤á¤Î¥¯¥í¥Ã¥¯¤ò»ØÄꤹ¤ë¤â¤Î¤Ç¡¢
72 ¤Î¤¤¤º¤ì¤«¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
74 ¤Ï¥·¥¹¥Æ¥àÁ´ÂΤǻÈÍѤµ¤ì¤ë¥¯¥í¥Ã¥¯¤Ç¡¢¤³¤Î¥¯¥í¥Ã¥¯¤ÏÊѹ¹²Äǽ¤Ç¤¢¤ë¡£
76 ¤ÏÊѹ¹¤µ¤ì¤ë¤³¤È¤Î¤Ê¤¤¥¯¥í¥Ã¥¯¤Ç¡¢(¥·¥¹¥Æ¥à»þ¹ï¤Î¼êÆ°¤Ç¤ÎÊѹ¹¤Ê¤É¤Î)
77 ¥·¥¹¥Æ¥à¥¯¥í¥Ã¥¯¤ÎÉÔϢ³¤ÊÊѲ½¤Î±Æ¶Á¤ò¼õ¤±¤Ê¤¤¡£
78 ¤³¤ì¤é¤Î¥¯¥í¥Ã¥¯¤Î¸½ºß¤ÎÃͤÏ
82 Linux 2.6.27 °Ê¹ß¤Ç¤Ï¡¢
83 °Ê²¼¤ÎÃͤΤ¤¤¯¤Ä¤«¤ò¥Ó¥Ã¥Èñ°Ì¤ÎÏÀÍýÏ (OR) ¤Ç»ØÄꤹ¤ë¤³¤È¤Ç¡¢
85 ¤Î¿¶Éñ¤¤¤òÊѹ¹¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£
88 ¿·¤·¤¯À¸À®¤µ¤ì¤ë¥ª¡¼¥×¥ó¥Õ¥¡¥¤¥ëµ½Ò (open file description) ¤Î
90 ¥Õ¥¡¥¤¥ë¥¹¥Æ¡¼¥¿¥¹¥Õ¥é¥°¤ò¥»¥Ã¥È¤¹¤ë¡£
91 ¤³¤Î¥Õ¥é¥°¤ò»È¤¦¤³¤È¤Ç¡¢
95 ¤òÄɲäǸƤӽФ¹É¬Íפ¬¤Ê¤¯¤Ê¤ë¡£
98 ¿·¤·¤¤¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ËÂФ·¤Æ
102 ¤³¤Î¥Õ¥é¥°¤¬Ìò¤ËΩ¤ÄÍýͳ¤Ë¤Ä¤¤¤Æ¤Ï¡¢
106 ¥Õ¥é¥°¤ÎÀâÌÀ¤ò»²¾È¤Î¤³¤È¡£
108 ¥Ð¡¼¥¸¥ç¥ó 2.6.26 °ÊÁ°¤Î Linux ¤Ç¤Ï¡¢
110 °ú¤¿ô¤Ï̤»ÈÍѤǤ¢¤ê¡¢0 ¤ò»ØÄꤷ¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
111 .SS timerfd_settime()
112 .BR timerfd_settime ()
113 ¤Ï¡¢¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿
115 ¤Ë¤è¤ê»²¾È¤µ¤ì¤ë¥¿¥¤¥Þ¡¼¤ò³«»Ï¤·¤¿¤êÄä»ß¤·¤¿¤ê¤¹¤ë¡£
118 °ú¤¿ô¤Ï¡¢¥¿¥¤¥Þ¡¼¤ÎËþλ»þ´Ö (expiration) ¤Î½é´üÃÍ¤È´Ö³Ö (interval) ¤ò
119 »ØÄꤹ¤ë¡£¤³¤Î°ú¤¿ô¤Ç»ÈÍѤµ¤ì¤Æ¤¤¤ë
121 ¹½Â¤ÂÎ¤Ë¤Ï 2 ¤Ä¤Î¥Õ¥£¡¼¥ë¥É¤¬¤¢¤ê¡¢³Æ¥Õ¥£¡¼¥ë¥É¤Ï
128 time_t tv_sec; /* Seconds */
129 long tv_nsec; /* Nanoseconds */
133 struct timespec it_interval; /* Interval for periodic timer */
134 struct timespec it_value; /* Initial expiration */
139 .I new_value.it_value
140 ¤Ï¥¿¥¤¥Þ¡¼¤ÎËþλ»þ´Ö¤Î½é´üÃͤò¡¢ÉäȥʥÎÉäǻØÄꤹ¤ë¡£
141 .I new_value.it_value
142 ¤Î¥Õ¥£¡¼¥ë¥É¤Î¤¦¤Á¾¯¤Ê¤¯¤È¤â°ìÊý¤Ë 0 °Ê³°¤ÎÃͤòÀßÄꤹ¤ë¤È¡¢
143 ¥¿¥¤¥Þ¡¼¤¬³«»Ï¤µ¤ì¤ë¡£
144 ξÊý¤Î¥Õ¥£¡¼¥ë¥É¤Ë 0 ¤òÀßÄꤹ¤ë¤È¡¢¥¿¥¤¥Þ¡¼¤¬Ää»ß¤¹¤ë¡£
146 .I new_value.it_interval
147 ¤Ï¥¿¥¤¥Þ¡¼¤Î°ì²óÌܤÎËþλ¸å¤Ë·«¤êÊÖ¤·¥¿¥¤¥Þ¡¼¤ÎËþλ´Ö³Ö¤ò¡¢ÉäȥʥÎÉäǻØÄꤹ¤ë¡£
148 .I new_value.it_interval
149 ¤Î¥Õ¥£¡¼¥ë¥É¤Î¤¦¤Á¾¯¤Ê¤¯¤È¤â°ìÊý¤Ë 0 °Ê³°¤ÎÃͤòÀßÄꤹ¤ë¤È¡¢
150 ·«¤êÊÖ¤·¥¿¥¤¥Þ¡¼¤¬Í¸ú¤Ë¤Ê¤ë¡£
151 ξÊý¤Î¥Õ¥£¡¼¥ë¥É¤Ë 0 ¤òÀßÄꤷ¤¿¾ì¹ç¡¢¥¿¥¤¥Þ¡¼¤Ï
152 .I new_value.it_value
153 ¤Ç»ØÄꤵ¤ì¤¿»þ´Ö¸å¤Ë¡¢°ì²ó¤À¤±Ëþλ¤·¤ÆÄä»ß¤¹¤ë¡£
159 0 ¤ÏÁêÂлþ¹ï¥¿¥¤¥Þ¡¼¤ò°ÕÌ£¤·¡¢
160 .I new_value.it_interval
163 ¤Ç»ØÄꤵ¤ì¤¿¥¯¥í¥Ã¥¯¤Î¸½ºß¤ÎÃͤ«¤é¤ÎÁêÂÐŪ¤Ê»þ¹ï¤ò»ØÄꤹ¤ë¡£
165 ¤ÏÀäÂлþ¹ï¥¿¥¤¥Þ¡¼¤ò°ÕÌ£¤·¡¢
166 .I new_value.it_interval
169 ¤Ç»ØÄꤵ¤ì¤¿¥¯¥í¥Ã¥¯¤ÎÀäÂлþ¹ï¤ò»ØÄꤹ¤ë¡£¤Ä¤Þ¤ê¡¢
171 .I new_value.it_interval
172 ¤Ç»ØÄꤵ¤ì¤¿»þ¹ï¤Ë㤷¤¿¤é¡¢¥¿¥¤¥Þ¡¼¤¬Ëþλ¤¹¤ë¡£
176 .BR timerfd_settime ()
177 ¤ò¸Æ¤Ó½Ð¤·¤¿»þÅÀ¤Ç¤Î¥¿¥¤¥Þ¡¼¤ÎÀßÄê¤òÊÝ»ý¤·¤¿¹½Â¤ÂΤ¬ÊÖ¤µ¤ì¤ë¡£
179 .BR timerfd_gettime ()
182 .SS timerfd_gettime()
183 .BR timerfd_gettime ()
184 ¤Ï¡¢¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿
186 ¤Ç»²¾È¤µ¤ì¤ë¥¿¥¤¥Þ¡¼¤Î¸½ºß¤ÎÀßÄ꤬Æþ¤Ã¤¿
193 ¥Õ¥£¡¼¥ë¥É¤Ï¡¢¥¿¥¤¥Þ¡¼¤¬¼¡¤ËËþλ¤¹¤ë¤Þ¤Ç¤Î»Ä¤ê»þ´Ö¤òÊÖ¤¹¡£
194 ¤³¤Î¹½Â¤ÂΤÎξÊý¤Î¥Õ¥£¡¼¥ë¥É¤¬ 0 ¤Ç¤¢¤ì¤Ð¡¢¥¿¥¤¥Þ¡¼¤Ï¸½ºßÄä»ß¤·¤Æ¤¤¤ë¡£
197 ¥Õ¥é¥°¤¬»ØÄꤵ¤ì¤¿¤«¤Ë´Ø¤ï¤é¤º¡¢¤³¤Î¥Õ¥£¡¼¥ë¥É¤Ï¾ï¤ËÁêÂÐÃͤ¬³ÊǼ¤µ¤ì¤ë¡£
200 ¥Õ¥£¡¼¥ë¥É¤Ï¡¢¥¿¥¤¥Þ¡¼¤Î´Ö³Ö¤òÊÖ¤¹¡£
201 ¤³¤Î¹½Â¤ÂΤÎξÊý¤Î¥Õ¥£¡¼¥ë¥É¤¬ 0 ¤Ç¤¢¤ì¤Ð¡¢¥¿¥¤¥Þ¡¼¤Ï
202 .I new_value.it_value
203 ¤Ç»ØÄꤵ¤ì¤¿»þ´Ö¸å¤Ë°ì²ó¤À¤±Ëþλ¤·¤ÆÄä»ß¤¹¤ë¤è¤¦¤ËÀßÄꤵ¤ì¤Æ¤¤¤ë¡£
204 .SS ¥¿¥¤¥Þ¡¼¡¦¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ËÂФ¹¤ëÁàºî
205 .BR timerfd_create ()
206 ¤¬ÊÖ¤¹¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ï°Ê²¼¤ÎÁàºî¤ò¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤ë¡£
209 .BR timerfd_settime ()
210 ¤ò»È¤Ã¤Æ¥¿¥¤¥Þ¡¼¤ÎÀßÄ꤬ºÇ¸åÊѹ¹¤µ¤ì¤Æ°Ê¹ß¡¢¤Þ¤¿¤Ï
212 ¤Î¸Æ¤Ó½Ð¤·¤ËºÇ¸å¤ËÀ®¸ù¤·¤Æ°Ê¹ß¤Ë¡¢¥¿¥¤¥Þ¡¼¤ÎËþ뤬°ì²ó°Ê¾åȯÀ¸¤·¤Æ¤¤¤ì¤Ð¡¢
214 ¤ËÅϤµ¤ì¤¿¥Ð¥Ã¥Õ¥¡¤Ë¡¢¥¿¥¤¥Þ¡¼Ëþλ²ó¿ô¤ò¼¨¤¹ 8 ¥Ð¥¤¥È¤Î unsigned ·¿¤ÎÀ°¿ô
217 (ÊÖ¤µ¤ì¤ëÃͤϥۥ¹¥È¥Ð¥¤¥È¥ª¡¼¥À¡¢¤Ä¤Þ¤ê¤½¤Î¥Û¥¹¥È¥Þ¥·¥ó¤Ë¤ª¤±¤ë
218 À°¿ô¤ÎÄ̾ï¤Î¥Ð¥¤¥È¥ª¡¼¥À¤Ç¤¢¤ë)¡£
221 ¤ò¹Ô¤Ã¤¿»þÅÀ¤Ç¥¿¥¤¥Þ¡¼¤ÎËþλ¤¬È¯À¸¤·¤Æ¤¤¤Ê¤±¤ì¤Ð¡¢
223 ¤ÏÄä»ß (block) ¤¹¤ë¡¢¤â¤·¤¯¤Ï¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤¬
224 ÈóÄä»ß (nonblocking) ¤ËÀßÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ï¥¨¥é¡¼
226 ¤Ç¼ºÇÔ¤¹¤ë (ÈóÄä»ß¥â¡¼¥É¤Ë¤¹¤ë¤Ë¤Ï¡¢
232 ¥Õ¥é¥°¤ò¥»¥Ã¥È¤¹¤ë)¡£
234 ÅϤµ¤ì¤¿¥Ð¥Ã¥Õ¥¡¤Î¥µ¥¤¥º¤¬ 8 ¥Ð¥¤¥È̤Ëþ¤Î¾ì¹ç¡¢
240 .BR poll "(2), " select "(2) (¤ÈƱÍͤÎÁàºî)"
241 °ì¤Ä°Ê¾å¤Î¥¿¥¤¥Þ¡¼Ëþλ¤¬È¯À¸¤·¤Æ¤¤¤ì¤Ð¡¢
242 ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ÏÆɤ߽Ф·²Äǽ¤È¤Ê¤ë
252 ¤³¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ï¡¢Â¾¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿Â¿½Å API ¤Ç¤¢¤ë
259 ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤¬¤½¤ì°Ê¹ß¤ÏɬÍפʤ¯¤Ê¤Ã¤¿ºÝ¤Ë¤Ï¡¢¥¯¥í¡¼¥º¤¹¤Ù¤¤Ç¤¢¤ë¡£
260 Ʊ¤¸ timer ¥ª¥Ö¥¸¥§¥¯¥È¤Ë´ØÏ¢ÉÕ¤±¤é¤ì¤¿¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤¬Á´¤Æ
261 ¥¯¥í¡¼¥º¤µ¤ì¤ë¤È¡¢¤½¤Î¥¿¥¤¥Þ¡¼¤Ï²ò½ü¤µ¤ì¡¢
262 ¤½¤Î¥ª¥Ö¥¸¥§¥¯¥ÈÍѤλñ¸»¤¬¥«¡¼¥Í¥ë¤Ë¤è¤ê²òÊü¤µ¤ì¤ë¡£
266 ¤¬¹Ô¤ï¤ì¤ë¤È¡¢»Ò¥×¥í¥»¥¹¤Ï
267 .BR timerfd_create ()
268 ¤Ë¤è¤êÀ¸À®¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Î¥³¥Ô¡¼¤ò
269 ·Ñ¾µ¤¹¤ë¡£¤½¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ï¡¢¿Æ¥×¥í¥»¥¹¤ÎÂбþ¤¹¤ë
270 ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ÈƱ¤¸¥¿¥¤¥Þ¡¼¥ª¥Ö¥¸¥§¥¯¥È¤ò»²¾È¤·¤Æ¤ª¤ê¡¢
273 ¤Ç¤âƱ¤¸¥¿¥¤¥Þ¡¼¤ÎËþλ¤Ë´Ø¤¹¤ë¾ðÊó¤¬ÊÖ¤µ¤ì¤ë¡£
275 .SS execve(2) ¤Ç¤Î°·¤¤
278 .BR timerfd_create ()
279 ¤Ë¤è¤êÀ¸À®¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ÏÊÝ»ý¤µ¤ì¡¢
280 ¥¿¥¤¥Þ¡¼¤¬³«»Ï¤µ¤ì¤Æ¤¤¤¿¾ì¹ç¤Ë¤Ï¥¿¥¤¥Þ¡¼¤ÎËþλ¤¬È¯À¸¤·Â³¤±¤ë¡£
283 .BR timerfd_create ()
284 ¤Ï¿·¤·¤¤¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤òÊÖ¤¹¡£
285 ¥¨¥é¡¼¤Î¾ì¹ç¡¢\-1 ¤òÊÖ¤·¡¢
287 ¤Ë¥¨¥é¡¼¤ò¼¨¤¹ÃͤòÀßÄꤹ¤ë¡£
289 .BR timerfd_settime ()
291 .BR timerfd_gettime ()
292 ¤ÏÀ®¸ù¤¹¤ë¤È 0 ¤òÊÖ¤¹¡£
293 ¥¨¥é¡¼¤Î¾ì¹ç¡¢\-1 ¤òÊÖ¤·¡¢
295 ¤Ë¥¨¥é¡¼¤ò¼¨¤¹ÃͤòÀßÄꤹ¤ë¡£
297 .BR timerfd_create ()
298 ¤Ï°Ê²¼¤Î¥¨¥é¡¼¤Ç¼ºÇÔ¤¹¤ë²ÄǽÀ¤¬¤¢¤ë¡£
310 ¤¬Ìµ¸ú¤Ç¤¢¤ë¡£¤â¤·¤¯¤Ï¡¢Linux 2.6.26 °ÊÁ°¤Î¾ì¹ç¤Ï
315 ¥ª¡¼¥×¥óºÑ¤ß¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Î¿ô¤¬¥×¥í¥»¥¹¤¢¤¿¤ê¤Î¾å¸Â¤Ë
319 ¥ª¡¼¥×¥óºÑ¤ß¤Î¥Õ¥¡¥¤¥ëÁí¿ô¤¬¥·¥¹¥Æ¥àÁ´ÂΤξå¸Â¤Ë㤷¤Æ¤¤¤¿¡£
322 (¥«¡¼¥Í¥ëÆâ¤Î) ̵̾ inode ¥Ç¥Ð¥¤¥¹¤ò¥Þ¥¦¥ó¥È¤Ç¤¤Ê¤«¤Ã¤¿¡£
325 ¥¿¥¤¥Þ¡¼¤òºîÀ®¤¹¤ë¤Î¤Ë½½Ê¬¤Ê¥«¡¼¥Í¥ë¥á¥â¥ê¤¬¤Ê¤«¤Ã¤¿¡£
327 .BR timerfd_settime ()
329 .BR timerfd_gettime ()
330 ¤Ï°Ê²¼¤Î¥¨¥é¡¼¤Ç¼ºÇÔ¤¹¤ë²ÄǽÀ¤¬¤¢¤ë¡£
334 ¤¬Í¸ú¤Ê¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ç¤Ê¤¤¡£
340 ¤¬Í¸ú¤Ê¥Ý¥¤¥ó¥¿¤Ç¤Ï¤Ê¤¤¡£
344 ¤¬Í¸ú¤Ê timerfd ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ç¤Ê¤¤¡£
346 .BR timerfd_settime ()
347 ¤Ï°Ê²¼¤Î¥¨¥é¡¼¤Ç¼ºÇÔ¤¹¤ë¤³¤È¤â¤¢¤ë¡£
351 ¤¬Å¬Àڤ˽é´ü²½¤µ¤ì¤Æ¤¤¤Ê¤¤
353 ¤Î°ì¤Ä¤¬ 0 ¤«¤é 999,999,999 ¤Þ¤Ç¤ÎÈϰϤËÆþ¤Ã¤Æ¤¤¤Ê¤¤)¡£
356 .\" This case only checked since 2.6.29, and 2.2.2[78].some-stable-version.
357 .\" In older kernel versions, no check was made for invalid flags.
361 ¤³¤ì¤é¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï¥«¡¼¥Í¥ë 2.6.25 °Ê¹ß¤Î Linux ¤ÇÍøÍѲÄǽ¤Ç¤¢¤ë¡£
362 ¥é¥¤¥Ö¥é¥ê¦¤Î¥µ¥Ý¡¼¥È¤Ï¥Ð¡¼¥¸¥ç¥ó 2.8 °Ê¹ß¤Î glibc ¤ÇÄ󶡤µ¤ì¤Æ¤¤¤ë¡£
364 ¤³¤ì¤é¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï Linux ¸ÇͤǤ¢¤ë¡£
366 °Ê²¼¤Î¥×¥í¥°¥é¥à¤Ï¡¢¥¿¥¤¥Þ¡¼¤òºîÀ®¤·¡¢¤½¤Î¿ÊĽ¤ò¥â¥Ë¥¿¡¼¤¹¤ë¤â¤Î¤Ç¤¢¤ë¡£
367 ¤³¤Î¥×¥í¥°¥é¥à¤ÏºÇÂç¤Ç 3 ¸Ä¤Î¥³¥Þ¥ó¥É¥é¥¤¥ó°ú¤¿ô¤ò¼è¤ê¡¢
368 Âè°ì°ú¤¿ô¤Ç¤Ï¥¿¥¤¥Þ¡¼¤ÎËþλ»þ´Ö¤Î½é´üÃÍ (Éÿôñ°Ì) ¤ò¡¢
369 ÂèÆó°ú¤¿ô¤Ç¤Ï¥¿¥¤¥Þ¡¼¤Î´Ö³Ö (Éÿôñ°Ì) ¤ò¡¢
370 Âè»°°ú¤¿ô¤Ç¤Ï¥¿¥¤¥Þ¡¼¤¬²¿²óËþλ¤·¤¿¤é¥×¥í¥°¥é¥à¤¬½ªÎ»¤¹¤ë¤«¤ò»ØÄꤹ¤ë¡£
371 ÂèÆó°ú¤¿ô¤ÈÂè»°°ú¤¿ô¤Ï¾Êά²Äǽ¤Ç¤¢¤ë¡£
373 °Ê²¼¤Î¥·¥§¥ë¤Î¥»¥Ã¥·¥ç¥ó¤Ï¤³¤Î¥×¥í¥°¥é¥à¤Î»ÈÍÑÎã¤ò¼¨¤·¤¿¤â¤Î¤Ç¤¢¤ë¡£
377 .RB "$" " a.out 3 1 100"
379 3.000: read: 1; total=1
380 4.000: read: 1; total=2
381 .BR "^Z " " # type control-Z to suspend the program"
382 [1]+ Stopped ./timerfd3_demo 3 1 100
383 .RB "$ " "fg" " # Resume execution after a few seconds"
385 9.660: read: 5; total=7
386 10.000: read: 1; total=8
387 11.000: read: 1; total=9
388 .BR "^C " " # type control-C to suspend the program"
391 .SS ¥×¥í¥°¥é¥à¤Î¥½¡¼¥¹
394 .\" The commented out code here is what we currently need until
395 .\" the required stuff is in glibc
398 .\"/* Link with -lrt */
399 .\"#define _GNU_SOURCE
400 .\"#include <sys/syscall.h>
401 .\"#include <unistd.h>
403 .\"#if defined(__i386__)
404 .\"#define __NR_timerfd_create 322
405 .\"#define __NR_timerfd_settime 325
406 .\"#define __NR_timerfd_gettime 326
410 .\"timerfd_create(int clockid, int flags)
412 .\" return syscall(__NR_timerfd_create, clockid, flags);
416 .\"timerfd_settime(int fd, int flags, struct itimerspec *new_value,
417 .\" struct itimerspec *curr_value)
419 .\" return syscall(__NR_timerfd_settime, fd, flags, new_value,
424 .\"timerfd_gettime(int fd, struct itimerspec *curr_value)
426 .\" return syscall(__NR_timerfd_gettime, fd, curr_value);
429 .\"#define TFD_TIMER_ABSTIME (1 << 0)
431 .\"////////////////////////////////////////////////////////////
432 #include <sys/timerfd.h>
437 #include <stdint.h> /* Definition of uint64_t */
439 #define handle_error(msg) \\
440 do { perror(msg); exit(EXIT_FAILURE); } while (0)
443 print_elapsed_time(void)
445 static struct timespec start;
446 struct timespec curr;
447 static int first_call = 1;
452 if (clock_gettime(CLOCK_MONOTONIC, &start) == \-1)
453 handle_error("clock_gettime");
456 if (clock_gettime(CLOCK_MONOTONIC, &curr) == \-1)
457 handle_error("clock_gettime");
459 secs = curr.tv_sec \- start.tv_sec;
460 nsecs = curr.tv_nsec \- start.tv_nsec;
465 printf("%d.%03d: ", secs, (nsecs + 500000) / 1000000);
469 main(int argc, char *argv[])
471 struct itimerspec new_value;
474 uint64_t exp, tot_exp;
477 if ((argc != 2) && (argc != 4)) {
478 fprintf(stderr, "%s init\-secs [interval\-secs max\-exp]\\n",
483 if (clock_gettime(CLOCK_REALTIME, &now) == \-1)
484 handle_error("clock_gettime");
486 /* Create a CLOCK_REALTIME absolute timer with initial
487 expiration and interval as specified in command line */
489 new_value.it_value.tv_sec = now.tv_sec + atoi(argv[1]);
490 new_value.it_value.tv_nsec = now.tv_nsec;
492 new_value.it_interval.tv_sec = 0;
495 new_value.it_interval.tv_sec = atoi(argv[2]);
496 max_exp = atoi(argv[3]);
498 new_value.it_interval.tv_nsec = 0;
500 fd = timerfd_create(CLOCK_REALTIME, 0);
502 handle_error("timerfd_create");
504 if (timerfd_settime(fd, TFD_TIMER_ABSTIME, &new_value, NULL) == \-1)
505 handle_error("timerfd_settime");
507 print_elapsed_time();
508 printf("timer started\\n");
510 for (tot_exp = 0; tot_exp < max_exp;) {
511 s = read(fd, &exp, sizeof(uint64_t));
512 if (s != sizeof(uint64_t))
513 handle_error("read");
516 print_elapsed_time();
517 printf("read: %llu; total=%llu\\n",
518 (unsigned long long) exp,
519 (unsigned long long) tot_exp);
528 .BR timerfd_create ()
529 ¤¬Âбþ¤·¤Æ¤¤¤ë clockid ¤Î¼ïÎà¤Ï
539 .BR timer_create (2),
540 .BR timer_gettime (2),
541 .BR timer_settime (2),