OSDN Git Service

Import translated manuals from JM CVS Repository.
[linuxjm/jm.git] / manual / LDP_man-pages / release / man2 / timerfd_create.2
1 .\" Copyright (C) 2008 Michael Kerrisk <mtk.manpages@gmail.com>
2 .\"
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.
7 .\"
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.
12 .\"
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,
16 .\" MA  02111-1307  USA
17 .\"
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
22 .\" 
23 .TH TIMERFD_CREATE 2 2009-03-10 Linux "Linux Programmer's Manual"
24 .SH Ì¾Á°
25 timerfd_create, timerfd_settime, timerfd_gettime \-
26 ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿·Ðͳ¤ÇÄÌÃΤ¹¤ë¥¿¥¤¥Þ¡¼
27 .SH ½ñ¼°
28 .nf
29 .B #include <sys/timerfd.h>
30 .sp
31 .BI "int timerfd_create(int " clockid ", int " flags );
32 .sp
33 .BI "int timerfd_settime(int " fd ", int " flags ,
34 .BI "                    const struct itimerspec *" new_value ,
35 .BI "                    struct itimerspec *" old_value );
36 .sp
37 .BI "int timerfd_gettime(int " fd ", struct itimerspec *" curr_value );
38 .fi
39 .SH ÀâÌÀ
40 ¤³¤ì¤é¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï¡¢ËþλÄÌÃΤò¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿·Ðͳ¤ÇÇÛÁ÷¤¹¤ë
41 ¥¿¥¤¥Þ¡¼¤ÎÀ¸À®¤ÈÁàºî¤ò¹Ô¤¦¡£
42 ¤³¤ì¤é¤Ï¡¢
43 .BR setitimer (2)
44 ¤ä
45 .BR timer_create (2)
46 ¤òÍѤ¤¤ëÊýË¡¤ÎÂå¤ï¤ê¤È¤Ê¤ë¤â¤Î¤Ç¤¢¤ê¡¢¤³¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ò
47 .BR select (2),
48 .BR poll (2),
49 .BR epoll (7)
50 ¤Ç´Æ»ë¤Ç¤­¤ë¤È¤¤¤¦ÍøÅÀ¤¬¤¢¤ë¡£
51
52 ¤³¤ì¤é¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤ò»È¤¦¤Î¤Ï¡¢¤½¤ì¤¾¤ì
53 .BR timer_create (2),
54 .BR timer_settime (2),
55 .BR timer_gettime (2)
56 ¤ò»È¤¦¤Î¤ÈƱÍͤǤ¢¤ë
57 .RB ( timer_getoverrun (2)
58 ¤ËÂбþ¤¹¤ë¤â¤Î¤Ï¤Ê¤¯¡¢°Ê²¼¤ÇÀâÌÀ¤¹¤ë¤è¤¦¤Ë
59 ¤³¤Îµ¡Ç½¤Ï
60 .BR read (2)
61 ¤Ë¤è¤êÄ󶡤µ¤ì¤ë)¡£
62 .\"
63 .SS timerfd_create()
64 .BR timerfd_create ()
65 ¤Ï¿·µ¬¤Î¥¿¥¤¥Þ¡¼¥ª¥Ö¥¸¥§¥¯¥È¤òÀ¸À®¤·¡¢¤½¤Î¥¿¥¤¥Þ¡¼¤ò»²¾È¤¹¤ë¥Õ¥¡¥¤¥ë
66 ¥Ç¥£¥¹¥¯¥ê¥×¥¿¤òÊÖ¤¹¡£
67 .I clockid
68 °ú¤­¿ô¤Ï¡¢¥¿¥¤¥Þ¡¼¤Î¿ÊĽ¤ò´ÉÍý¤¹¤ë¤¿¤á¤Î¥¯¥í¥Ã¥¯¤ò»ØÄꤹ¤ë¤â¤Î¤Ç¡¢
69 .B CLOCK_REALTIME
70 ¤«
71 .B CLOCK_MONOTONIC
72 ¤Î¤¤¤º¤ì¤«¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
73 .B CLOCK_REALTIME
74 ¤Ï¥·¥¹¥Æ¥àÁ´ÂΤǻÈÍѤµ¤ì¤ë¥¯¥í¥Ã¥¯¤Ç¡¢¤³¤Î¥¯¥í¥Ã¥¯¤ÏÊѹ¹²Äǽ¤Ç¤¢¤ë¡£
75 .B CLOCK_MONOTONIC
76 ¤ÏÊѹ¹¤µ¤ì¤ë¤³¤È¤Î¤Ê¤¤¥¯¥í¥Ã¥¯¤Ç¡¢(¥·¥¹¥Æ¥à»þ¹ï¤Î¼êÆ°¤Ç¤ÎÊѹ¹¤Ê¤É¤Î)
77 ¥·¥¹¥Æ¥à¥¯¥í¥Ã¥¯¤ÎÉÔϢ³¤ÊÊѲ½¤Î±Æ¶Á¤ò¼õ¤±¤Ê¤¤¡£
78 ¤³¤ì¤é¤Î¥¯¥í¥Ã¥¯¤Î¸½ºß¤ÎÃͤÏ
79 .BR clock_gettime (2)
80 ¤ò»È¤Ã¤Æ¼èÆÀ¤Ç¤­¤ë¡£
81
82 Linux 2.6.27 °Ê¹ß¤Ç¤Ï¡¢
83 °Ê²¼¤ÎÃͤΤ¤¤¯¤Ä¤«¤ò¥Ó¥Ã¥Èñ°Ì¤ÎÏÀÍýÏ (OR) ¤Ç»ØÄꤹ¤ë¤³¤È¤Ç¡¢
84 .BR timerfd_create ()
85 ¤Î¿¶Éñ¤¤¤òÊѹ¹¤¹¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
86 .TP 14
87 .B TFD_NONBLOCK
88 ¿·¤·¤¯À¸À®¤µ¤ì¤ë¥ª¡¼¥×¥ó¥Õ¥¡¥¤¥ëµ­½Ò (open file description) ¤Î
89 .B O_NONBLOCK
90 ¥Õ¥¡¥¤¥ë¥¹¥Æ¡¼¥¿¥¹¥Õ¥é¥°¤ò¥»¥Ã¥È¤¹¤ë¡£
91 ¤³¤Î¥Õ¥é¥°¤ò»È¤¦¤³¤È¤Ç¡¢
92 .B O_NONBLOCK
93 ¤ò¥»¥Ã¥È¤¹¤ë¤¿¤á¤Ë
94 .BR fcntl (2)
95 ¤òÄɲäǸƤӽФ¹É¬Íפ¬¤Ê¤¯¤Ê¤ë¡£
96 .TP
97 .B TFD_CLOEXEC
98 ¿·¤·¤¤¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ËÂФ·¤Æ
99 close-on-exec
100 .RB ( FD_CLOEXEC )
101 ¥Õ¥é¥°¤ò¥»¥Ã¥È¤¹¤ë¡£
102 ¤³¤Î¥Õ¥é¥°¤¬Ìò¤ËΩ¤ÄÍýͳ¤Ë¤Ä¤¤¤Æ¤Ï¡¢
103 .BR open (2)
104 ¤Î
105 .B O_CLOEXEC
106 ¥Õ¥é¥°¤ÎÀâÌÀ¤ò»²¾È¤Î¤³¤È¡£
107 .PP
108 ¥Ð¡¼¥¸¥ç¥ó 2.6.26 °ÊÁ°¤Î Linux ¤Ç¤Ï¡¢
109 .I flags
110 °ú¤­¿ô¤Ï̤»ÈÍѤǤ¢¤ê¡¢0 ¤ò»ØÄꤷ¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
111 .SS timerfd_settime()
112 .BR timerfd_settime ()
113 ¤Ï¡¢¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿
114 .I fd
115 ¤Ë¤è¤ê»²¾È¤µ¤ì¤ë¥¿¥¤¥Þ¡¼¤ò³«»Ï¤·¤¿¤êÄä»ß¤·¤¿¤ê¤¹¤ë¡£
116
117 .I new_value
118 °ú¤­¿ô¤Ï¡¢¥¿¥¤¥Þ¡¼¤ÎËþλ»þ´Ö (expiration) ¤Î½é´üÃͤȴֳ֠(interval) ¤ò
119 »ØÄꤹ¤ë¡£¤³¤Î°ú¤­¿ô¤Ç»ÈÍѤµ¤ì¤Æ¤¤¤ë
120 .I itimerspec
121 ¹½Â¤ÂΤˤϠ2 ¤Ä¤Î¥Õ¥£¡¼¥ë¥É¤¬¤¢¤ê¡¢³Æ¥Õ¥£¡¼¥ë¥É¤Ï
122 .I timespec
123 ·¿¤Î¹½Â¤ÂΤǤ¢¤ë¡£
124 .in +4n
125 .nf
126
127 struct timespec {
128     time_t tv_sec;                /* Seconds */
129     long   tv_nsec;               /* Nanoseconds */
130 };
131
132 struct itimerspec {
133     struct timespec it_interval;  /* Interval for periodic timer */
134     struct timespec it_value;     /* Initial expiration */
135 };
136 .fi
137 .in
138 .PP
139 .I new_value.it_value
140 ¤Ï¥¿¥¤¥Þ¡¼¤ÎËþλ»þ´Ö¤Î½é´üÃͤò¡¢ÉäȥʥÎÉäǻØÄꤹ¤ë¡£
141 .I new_value.it_value
142 ¤Î¥Õ¥£¡¼¥ë¥É¤Î¤¦¤Á¾¯¤Ê¤¯¤È¤â°ìÊý¤Ë 0 °Ê³°¤ÎÃͤòÀßÄꤹ¤ë¤È¡¢
143 ¥¿¥¤¥Þ¡¼¤¬³«»Ï¤µ¤ì¤ë¡£
144 ξÊý¤Î¥Õ¥£¡¼¥ë¥É¤Ë 0 ¤òÀßÄꤹ¤ë¤È¡¢¥¿¥¤¥Þ¡¼¤¬Ää»ß¤¹¤ë¡£
145
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 ¤Ç»ØÄꤵ¤ì¤¿»þ´Ö¸å¤Ë¡¢°ì²ó¤À¤±Ëþλ¤·¤ÆÄä»ß¤¹¤ë¡£
154
155 .I flags
156 °ú¤­¿ô¤Ë¤Ï 0 ¤«
157 .B TFD_TIMER_ABSTIME
158 ¤ò»ØÄꤹ¤ë¡£
159 0 ¤ÏÁêÂлþ¹ï¥¿¥¤¥Þ¡¼¤ò°ÕÌ£¤·¡¢
160 .I new_value.it_interval
161 ¤Ç¤Ï
162 .I clockid
163 ¤Ç»ØÄꤵ¤ì¤¿¥¯¥í¥Ã¥¯¤Î¸½ºß¤ÎÃͤ«¤é¤ÎÁêÂÐŪ¤Ê»þ¹ï¤ò»ØÄꤹ¤ë¡£
164 .B TFD_TIMER_ABSTIME
165 ¤ÏÀäÂлþ¹ï¥¿¥¤¥Þ¡¼¤ò°ÕÌ£¤·¡¢
166 .I new_value.it_interval
167 ¤Ç¤Ï
168 .I clockid
169 ¤Ç»ØÄꤵ¤ì¤¿¥¯¥í¥Ã¥¯¤ÎÀäÂлþ¹ï¤ò»ØÄꤹ¤ë¡£¤Ä¤Þ¤ê¡¢
170 ¥¯¥í¥Ã¥¯¤ÎÃͤ¬
171 .I new_value.it_interval
172 ¤Ç»ØÄꤵ¤ì¤¿»þ¹ï¤Ë㤷¤¿¤é¡¢¥¿¥¤¥Þ¡¼¤¬Ëþλ¤¹¤ë¡£
173
174 .I old_value
175 °ú¤­¿ô¤òÄ̤¸¤Æ¡¢
176 .BR timerfd_settime ()
177 ¤ò¸Æ¤Ó½Ð¤·¤¿»þÅÀ¤Ç¤Î¥¿¥¤¥Þ¡¼¤ÎÀßÄê¤òÊÝ»ý¤·¤¿¹½Â¤ÂΤ¬ÊÖ¤µ¤ì¤ë¡£
178 ²¼µ­¤Î
179 .BR timerfd_gettime ()
180 ¤ÎÀâÌÀ¤ò»²¾È¡£
181 .\"
182 .SS timerfd_gettime()
183 .BR timerfd_gettime ()
184 ¤Ï¡¢¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿
185 .I fd
186 ¤Ç»²¾È¤µ¤ì¤ë¥¿¥¤¥Þ¡¼¤Î¸½ºß¤ÎÀßÄ꤬Æþ¤Ã¤¿
187 .I itimerspec
188 ¹½Â¤ÂΤò¡¢
189 .I curr_value
190 ¤Ë³ÊǼ¤·¤ÆÊÖ¤¹¡£
191
192 .I it_value
193 ¥Õ¥£¡¼¥ë¥É¤Ï¡¢¥¿¥¤¥Þ¡¼¤¬¼¡¤ËËþλ¤¹¤ë¤Þ¤Ç¤Î»Ä¤ê»þ´Ö¤òÊÖ¤¹¡£
194 ¤³¤Î¹½Â¤ÂΤÎξÊý¤Î¥Õ¥£¡¼¥ë¥É¤¬ 0 ¤Ç¤¢¤ì¤Ð¡¢¥¿¥¤¥Þ¡¼¤Ï¸½ºßÄä»ß¤·¤Æ¤¤¤ë¡£
195 ¥¿¥¤¥Þ¡¼ÀßÄê»þ¤Ë
196 .B TFD_TIMER_ABSTIME
197 ¥Õ¥é¥°¤¬»ØÄꤵ¤ì¤¿¤«¤Ë´Ø¤ï¤é¤º¡¢¤³¤Î¥Õ¥£¡¼¥ë¥É¤Ï¾ï¤ËÁêÂÐÃͤ¬³ÊǼ¤µ¤ì¤ë¡£
198
199 .I it_interval
200 ¥Õ¥£¡¼¥ë¥É¤Ï¡¢¥¿¥¤¥Þ¡¼¤Î´Ö³Ö¤òÊÖ¤¹¡£
201 ¤³¤Î¹½Â¤ÂΤÎξÊý¤Î¥Õ¥£¡¼¥ë¥É¤¬ 0 ¤Ç¤¢¤ì¤Ð¡¢¥¿¥¤¥Þ¡¼¤Ï
202 .I new_value.it_value
203 ¤Ç»ØÄꤵ¤ì¤¿»þ´Ö¸å¤Ë°ì²ó¤À¤±Ëþλ¤·¤ÆÄä»ß¤¹¤ë¤è¤¦¤ËÀßÄꤵ¤ì¤Æ¤¤¤ë¡£
204 .SS ¥¿¥¤¥Þ¡¼¡¦¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ËÂФ¹¤ëÁàºî
205 .BR timerfd_create ()
206 ¤¬ÊÖ¤¹¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ï°Ê²¼¤ÎÁàºî¤ò¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤ë¡£
207 .TP
208 .BR read (2)
209 .BR timerfd_settime ()
210 ¤ò»È¤Ã¤Æ¥¿¥¤¥Þ¡¼¤ÎÀßÄ꤬ºÇ¸åÊѹ¹¤µ¤ì¤Æ°Ê¹ß¡¢¤Þ¤¿¤Ï
211 .BR read (2)
212 ¤Î¸Æ¤Ó½Ð¤·¤ËºÇ¸å¤ËÀ®¸ù¤·¤Æ°Ê¹ß¤Ë¡¢¥¿¥¤¥Þ¡¼¤ÎËþ뤬°ì²ó°Ê¾åȯÀ¸¤·¤Æ¤¤¤ì¤Ð¡¢
213 .BR read (2)
214 ¤ËÅϤµ¤ì¤¿¥Ð¥Ã¥Õ¥¡¤Ë¡¢¥¿¥¤¥Þ¡¼Ëþλ²ó¿ô¤ò¼¨¤¹ 8 ¥Ð¥¤¥È¤Î unsigned ·¿¤ÎÀ°¿ô
215 .RI ( uint64_t )
216 ¤¬ÊÖ¤µ¤ì¤ë
217 (ÊÖ¤µ¤ì¤ëÃͤϥۥ¹¥È¥Ð¥¤¥È¥ª¡¼¥À¡¢¤Ä¤Þ¤ê¤½¤Î¥Û¥¹¥È¥Þ¥·¥ó¤Ë¤ª¤±¤ë
218 À°¿ô¤ÎÄ̾ï¤Î¥Ð¥¤¥È¥ª¡¼¥À¤Ç¤¢¤ë)¡£
219 .IP
220 .BR read (2)
221 ¤ò¹Ô¤Ã¤¿»þÅÀ¤Ç¥¿¥¤¥Þ¡¼¤ÎËþλ¤¬È¯À¸¤·¤Æ¤¤¤Ê¤±¤ì¤Ð¡¢
222 .BR read (2)
223 ¤ÏÄä»ß (block) ¤¹¤ë¡¢¤â¤·¤¯¤Ï¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤¬
224 ÈóÄä»ß (nonblocking) ¤ËÀßÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ï¥¨¥é¡¼
225 .B EAGAIN
226 ¤Ç¼ºÇÔ¤¹¤ë (ÈóÄä»ß¥â¡¼¥É¤Ë¤¹¤ë¤Ë¤Ï¡¢
227 .BR fcntl (2)
228 ¤Î
229 .B F_SETFL
230 Ì¿Îá¤Ç
231 .B O_NONBLOCK
232 ¥Õ¥é¥°¤ò¥»¥Ã¥È¤¹¤ë)¡£
233 .IP
234 ÅϤµ¤ì¤¿¥Ð¥Ã¥Õ¥¡¤Î¥µ¥¤¥º¤¬ 8 ¥Ð¥¤¥È̤Ëþ¤Î¾ì¹ç¡¢
235 .BR read (2)
236 ¤Ï¥¨¥é¡¼
237 .B EINVAL
238 ¤Ç¼ºÇÔ¤¹¤ë¡£
239 .TP
240 .BR poll "(2), " select "(2) (¤ÈƱÍͤÎÁàºî)"
241 °ì¤Ä°Ê¾å¤Î¥¿¥¤¥Þ¡¼Ëþλ¤¬È¯À¸¤·¤Æ¤¤¤ì¤Ð¡¢
242 ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ÏÆɤ߽Ф·²Äǽ¤È¤Ê¤ë
243 .RB ( select (2)
244 ¤Î
245 .I readfds
246 °ú¤­¿ô¤ä
247 .BR poll (2)
248 ¤Î
249 .B POLLIN
250 ¥Õ¥é¥°)¡£
251 .IP
252 ¤³¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ï¡¢Â¾¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿Â¿½Å API ¤Ç¤¢¤ë
253 .BR pselect (2),
254 .BR ppoll (2),
255 .BR epoll (7)
256 ¤â¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤ë¡£
257 .TP
258 .BR close (2)
259 ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤¬¤½¤ì°Ê¹ß¤ÏɬÍפʤ¯¤Ê¤Ã¤¿ºÝ¤Ë¤Ï¡¢¥¯¥í¡¼¥º¤¹¤Ù¤­¤Ç¤¢¤ë¡£
260 Ʊ¤¸ timer ¥ª¥Ö¥¸¥§¥¯¥È¤Ë´ØÏ¢ÉÕ¤±¤é¤ì¤¿¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤¬Á´¤Æ
261 ¥¯¥í¡¼¥º¤µ¤ì¤ë¤È¡¢¤½¤Î¥¿¥¤¥Þ¡¼¤Ï²ò½ü¤µ¤ì¡¢
262 ¤½¤Î¥ª¥Ö¥¸¥§¥¯¥ÈÍѤλñ¸»¤¬¥«¡¼¥Í¥ë¤Ë¤è¤ê²òÊü¤µ¤ì¤ë¡£
263 .\"
264 .SS fork(2) ¤Ç¤Î°·¤¤
265 .BR fork (2)
266 ¤¬¹Ô¤ï¤ì¤ë¤È¡¢»Ò¥×¥í¥»¥¹¤Ï
267 .BR timerfd_create ()
268 ¤Ë¤è¤êÀ¸À®¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Î¥³¥Ô¡¼¤ò
269 ·Ñ¾µ¤¹¤ë¡£¤½¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ï¡¢¿Æ¥×¥í¥»¥¹¤ÎÂбþ¤¹¤ë
270 ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ÈƱ¤¸¥¿¥¤¥Þ¡¼¥ª¥Ö¥¸¥§¥¯¥È¤ò»²¾È¤·¤Æ¤ª¤ê¡¢
271 »Ò¥×¥í¥»¥¹¤Î
272 .BR read (2)
273 ¤Ç¤âƱ¤¸¥¿¥¤¥Þ¡¼¤ÎËþλ¤Ë´Ø¤¹¤ë¾ðÊó¤¬ÊÖ¤µ¤ì¤ë¡£
274 .\"
275 .SS execve(2) ¤Ç¤Î°·¤¤
276 .BR execve (2)
277 ¤ÎÁ°¸å¤Ç
278 .BR timerfd_create ()
279 ¤Ë¤è¤êÀ¸À®¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ÏÊÝ»ý¤µ¤ì¡¢
280 ¥¿¥¤¥Þ¡¼¤¬³«»Ï¤µ¤ì¤Æ¤¤¤¿¾ì¹ç¤Ë¤Ï¥¿¥¤¥Þ¡¼¤ÎËþλ¤¬È¯À¸¤·Â³¤±¤ë¡£
281 .SH ÊÖ¤êÃÍ
282 À®¸ù¤¹¤ë¤È¡¢
283 .BR timerfd_create ()
284 ¤Ï¿·¤·¤¤¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤òÊÖ¤¹¡£
285 ¥¨¥é¡¼¤Î¾ì¹ç¡¢\-1 ¤òÊÖ¤·¡¢
286 .I errno
287 ¤Ë¥¨¥é¡¼¤ò¼¨¤¹ÃͤòÀßÄꤹ¤ë¡£
288
289 .BR timerfd_settime ()
290 ¤È
291 .BR timerfd_gettime ()
292 ¤ÏÀ®¸ù¤¹¤ë¤È 0 ¤òÊÖ¤¹¡£
293 ¥¨¥é¡¼¤Î¾ì¹ç¡¢\-1 ¤òÊÖ¤·¡¢
294 .I errno
295 ¤Ë¥¨¥é¡¼¤ò¼¨¤¹ÃͤòÀßÄꤹ¤ë¡£
296 .SH ¥¨¥é¡¼
297 .BR timerfd_create ()
298 ¤Ï°Ê²¼¤Î¥¨¥é¡¼¤Ç¼ºÇÔ¤¹¤ë²ÄǽÀ­¤¬¤¢¤ë¡£
299 .TP
300 .B EINVAL
301 .I clockid
302 °ú¤­¿ô¤¬
303 .B CLOCK_MONOTONIC
304 ¤Ç¤â
305 .B CLOCK_REALTIME
306 ¤Ç¤â¤Ê¤¤¡£
307 .TP
308 .B EINVAL
309 .I flags
310 ¤¬Ìµ¸ú¤Ç¤¢¤ë¡£¤â¤·¤¯¤Ï¡¢Linux 2.6.26 °ÊÁ°¤Î¾ì¹ç¤Ï
311 .I flags
312 ¤¬ 0 °Ê³°¤Ç¤¢¤ë¡£
313 .TP
314 .B EMFILE
315 ¥ª¡¼¥×¥óºÑ¤ß¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Î¿ô¤¬¥×¥í¥»¥¹¤¢¤¿¤ê¤Î¾å¸Â¤Ë
316 㤷¤Æ¤¤¤¿¡£
317 .TP
318 .B ENFILE
319 ¥ª¡¼¥×¥óºÑ¤ß¤Î¥Õ¥¡¥¤¥ëÁí¿ô¤¬¥·¥¹¥Æ¥àÁ´ÂΤξå¸Â¤Ë㤷¤Æ¤¤¤¿¡£
320 .TP
321 .B ENODEV
322 (¥«¡¼¥Í¥ëÆâ¤Î) ÌµÌ¾ inode ¥Ç¥Ð¥¤¥¹¤ò¥Þ¥¦¥ó¥È¤Ç¤­¤Ê¤«¤Ã¤¿¡£
323 .TP
324 .B ENOMEM
325 ¥¿¥¤¥Þ¡¼¤òºîÀ®¤¹¤ë¤Î¤Ë½½Ê¬¤Ê¥«¡¼¥Í¥ë¥á¥â¥ê¤¬¤Ê¤«¤Ã¤¿¡£
326 .PP
327 .BR timerfd_settime ()
328 ¤È
329 .BR timerfd_gettime ()
330 ¤Ï°Ê²¼¤Î¥¨¥é¡¼¤Ç¼ºÇÔ¤¹¤ë²ÄǽÀ­¤¬¤¢¤ë¡£
331 .TP
332 .B EBADF
333 .I fd
334 ¤¬Í­¸ú¤Ê¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ç¤Ê¤¤¡£
335 .TP
336 .B EFAULT
337 .IR new_value ,
338 .IR old_value ,
339 .I curr_value
340 ¤¬Í­¸ú¤Ê¥Ý¥¤¥ó¥¿¤Ç¤Ï¤Ê¤¤¡£
341 .TP
342 .B EINVAL
343 .I fd
344 ¤¬Í­¸ú¤Ê timerfd ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ç¤Ê¤¤¡£
345 .PP
346 .BR timerfd_settime ()
347 ¤Ï°Ê²¼¤Î¥¨¥é¡¼¤Ç¼ºÇÔ¤¹¤ë¤³¤È¤â¤¢¤ë¡£
348 .TP
349 .B EINVAL
350 .I new_value
351 ¤¬Å¬Àڤ˽é´ü²½¤µ¤ì¤Æ¤¤¤Ê¤¤
352 .RI ( tv_nsec
353 ¤Î°ì¤Ä¤¬ 0 ¤«¤é 999,999,999 ¤Þ¤Ç¤ÎÈϰϤËÆþ¤Ã¤Æ¤¤¤Ê¤¤)¡£
354 .TP
355 .B EINVAL
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.
358 .I flags
359 ¤¬Ìµ¸ú¤Ç¤¢¤ë¡£
360 .SH ¥Ð¡¼¥¸¥ç¥ó
361 ¤³¤ì¤é¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï¥«¡¼¥Í¥ë 2.6.25 °Ê¹ß¤Î Linux ¤ÇÍøÍѲÄǽ¤Ç¤¢¤ë¡£
362 ¥é¥¤¥Ö¥é¥ê¦¤Î¥µ¥Ý¡¼¥È¤Ï¥Ð¡¼¥¸¥ç¥ó 2.8 °Ê¹ß¤Î glibc ¤ÇÄ󶡤µ¤ì¤Æ¤¤¤ë¡£
363 .SH ½àµò
364 ¤³¤ì¤é¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï Linux ¸ÇÍ­¤Ç¤¢¤ë¡£
365 .SH Îã
366 °Ê²¼¤Î¥×¥í¥°¥é¥à¤Ï¡¢¥¿¥¤¥Þ¡¼¤òºîÀ®¤·¡¢¤½¤Î¿ÊĽ¤ò¥â¥Ë¥¿¡¼¤¹¤ë¤â¤Î¤Ç¤¢¤ë¡£
367 ¤³¤Î¥×¥í¥°¥é¥à¤ÏºÇÂç¤Ç 3 ¸Ä¤Î¥³¥Þ¥ó¥É¥é¥¤¥ó°ú¤­¿ô¤ò¼è¤ê¡¢
368 Âè°ì°ú¤­¿ô¤Ç¤Ï¥¿¥¤¥Þ¡¼¤ÎËþλ»þ´Ö¤Î½é´üÃÍ (Éÿôñ°Ì) ¤ò¡¢
369 ÂèÆó°ú¤­¿ô¤Ç¤Ï¥¿¥¤¥Þ¡¼¤Î´Ö³Ö (Éÿôñ°Ì) ¤ò¡¢
370 Âè»°°ú¤­¿ô¤Ç¤Ï¥¿¥¤¥Þ¡¼¤¬²¿²óËþλ¤·¤¿¤é¥×¥í¥°¥é¥à¤¬½ªÎ»¤¹¤ë¤«¤ò»ØÄꤹ¤ë¡£
371 ÂèÆó°ú¤­¿ô¤ÈÂè»°°ú¤­¿ô¤Ï¾Êά²Äǽ¤Ç¤¢¤ë¡£
372
373 °Ê²¼¤Î¥·¥§¥ë¤Î¥»¥Ã¥·¥ç¥ó¤Ï¤³¤Î¥×¥í¥°¥é¥à¤Î»ÈÍÑÎã¤ò¼¨¤·¤¿¤â¤Î¤Ç¤¢¤ë¡£
374 .in +4n
375 .nf
376
377 .RB "$" " a.out 3 1 100"
378 0.000: timer started
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"
384 a.out 3 1 100
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"
389 .fi
390 .in
391 .SS ¥×¥í¥°¥é¥à¤Î¥½¡¼¥¹
392 \&
393 .nf
394 .\" The commented out code here is what we currently need until
395 .\" the required stuff is in glibc
396 .\"
397 .\"
398 .\"/* Link with -lrt */
399 .\"#define _GNU_SOURCE
400 .\"#include <sys/syscall.h>
401 .\"#include <unistd.h>
402 .\"#include <time.h>
403 .\"#if defined(__i386__)
404 .\"#define __NR_timerfd_create 322
405 .\"#define __NR_timerfd_settime 325
406 .\"#define __NR_timerfd_gettime 326
407 .\"#endif
408 .\"
409 .\"static int
410 .\"timerfd_create(int clockid, int flags)
411 .\"{
412 .\"    return syscall(__NR_timerfd_create, clockid, flags);
413 .\"}
414 .\"
415 .\"static int
416 .\"timerfd_settime(int fd, int flags, struct itimerspec *new_value,
417 .\"        struct itimerspec *curr_value)
418 .\"{
419 .\"    return syscall(__NR_timerfd_settime, fd, flags, new_value,
420 .\"                   curr_value);
421 .\"}
422 .\"
423 .\"static int
424 .\"timerfd_gettime(int fd, struct itimerspec *curr_value)
425 .\"{
426 .\"    return syscall(__NR_timerfd_gettime, fd, curr_value);
427 .\"}
428 .\"
429 .\"#define TFD_TIMER_ABSTIME (1 << 0)
430 .\"
431 .\"////////////////////////////////////////////////////////////
432 #include <sys/timerfd.h>
433 #include <time.h>
434 #include <unistd.h>
435 #include <stdlib.h>
436 #include <stdio.h>
437 #include <stdint.h>        /* Definition of uint64_t */
438
439 #define handle_error(msg) \\
440         do { perror(msg); exit(EXIT_FAILURE); } while (0)
441
442 static void
443 print_elapsed_time(void)
444 {
445     static struct timespec start;
446     struct timespec curr;
447     static int first_call = 1;
448     int secs, nsecs;
449
450     if (first_call) {
451         first_call = 0;
452         if (clock_gettime(CLOCK_MONOTONIC, &start) == \-1)
453             handle_error("clock_gettime");
454     }
455
456     if (clock_gettime(CLOCK_MONOTONIC, &curr) == \-1)
457         handle_error("clock_gettime");
458
459     secs = curr.tv_sec \- start.tv_sec;
460     nsecs = curr.tv_nsec \- start.tv_nsec;
461     if (nsecs < 0) {
462         secs\-\-;
463         nsecs += 1000000000;
464     }
465     printf("%d.%03d: ", secs, (nsecs + 500000) / 1000000);
466 }
467
468 int
469 main(int argc, char *argv[])
470 {
471     struct itimerspec new_value;
472     int max_exp, fd;
473     struct timespec now;
474     uint64_t exp, tot_exp;
475     ssize_t s;
476
477     if ((argc != 2) && (argc != 4)) {
478         fprintf(stderr, "%s init\-secs [interval\-secs max\-exp]\\n",
479                 argv[0]);
480         exit(EXIT_FAILURE);
481     }
482
483     if (clock_gettime(CLOCK_REALTIME, &now) == \-1)
484         handle_error("clock_gettime");
485
486     /* Create a CLOCK_REALTIME absolute timer with initial
487        expiration and interval as specified in command line */
488
489     new_value.it_value.tv_sec = now.tv_sec + atoi(argv[1]);
490     new_value.it_value.tv_nsec = now.tv_nsec;
491     if (argc == 2) {
492         new_value.it_interval.tv_sec = 0;
493         max_exp = 1;
494     } else {
495         new_value.it_interval.tv_sec = atoi(argv[2]);
496         max_exp = atoi(argv[3]);
497     }
498     new_value.it_interval.tv_nsec = 0;
499
500     fd = timerfd_create(CLOCK_REALTIME, 0);
501     if (fd == \-1)
502         handle_error("timerfd_create");
503
504     if (timerfd_settime(fd, TFD_TIMER_ABSTIME, &new_value, NULL) == \-1)
505         handle_error("timerfd_settime");
506
507     print_elapsed_time();
508     printf("timer started\\n");
509
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");
514
515         tot_exp += exp;
516         print_elapsed_time();
517         printf("read: %llu; total=%llu\\n",
518                 (unsigned long long) exp,
519                 (unsigned long long) tot_exp);
520     }
521
522     exit(EXIT_SUCCESS);
523 }
524 .fi
525 .SH ¥Ð¥°
526 ¸½ºß¤Î¤È¤³¤í¡¢
527 .\" 2.6.29
528 .BR timerfd_create ()
529 ¤¬Âбþ¤·¤Æ¤¤¤ë clockid ¤Î¼ïÎà¤Ï
530 .BR timer_create (2)
531 ¤è¤ê¤â¾¯¤Ê¤¤¡£
532 .SH ´ØÏ¢¹àÌÜ
533 .BR eventfd (2),
534 .BR poll (2),
535 .BR read (2),
536 .BR select (2),
537 .BR setitimer (2),
538 .BR signalfd (2),
539 .BR timer_create (2),
540 .BR timer_gettime (2),
541 .BR timer_settime (2),
542 .BR epoll (7),
543 .BR time (7)