1 .\" Copyright (C) 2008 Michael Kerrisk <mtk.manpages@gmail.com>
2 .\" starting from a version by Davide Libenzi <davidel@xmailserver.org>
4 .\" This program is free software; you can redistribute it and/or modify
5 .\" it under the terms of the GNU General Public License as published by
6 .\" the Free Software Foundation; either version 2 of the License, or
7 .\" (at your option) any later version.
9 .\" This program is distributed in the hope that it will be useful,
10 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
11 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 .\" GNU General Public License for more details.
14 .\" You should have received a copy of the GNU General Public License
15 .\" along with this program; if not, write to the Free Software
16 .\" Foundation, Inc., 59 Temple Place, Suite 330, Boston,
19 .\" Japanese Version Copyright (c) 2008 Akihiro MOTOKI
20 .\" all rights reserved.
21 .\" Translated 2008-04-06, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.79
22 .\" Updated 2008-11-10, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.13
23 .\" Updated 2009-02-23, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.18
25 .TH SIGNALFD 2 2009-01-13 Linux "Linux Programmer's Manual"
28 .\"O signalfd \- create a file descriptor for accepting signals
29 signalfd \- ¥·¥°¥Ê¥ë¼õ¤±ÉÕ¤±ÍѤΥե¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤òÀ¸À®¤¹¤ë
32 .B #include <sys/signalfd.h>
34 .BI "int signalfd(int " fd ", const sigset_t *" mask ", int " flags );
38 .\"O creates a file descriptor that can be used to accept signals
39 .\"O targeted at the caller.
40 .\"O This provides an alternative to the use of a signal handler or
41 .\"O .BR sigwaitinfo (2),
42 .\"O and has the advantage that the file descriptor may be monitored by
48 ¤Ï¡¢¸Æ¤Ó½Ð¤·¸µ°¸¤Æ¤Î¥·¥°¥Ê¥ë¤ò¼õ¤±ÉÕ¤±¤ë¤¿¤á¤Ë»ÈÍѤµ¤ì¤ë¥Õ¥¡¥¤¥ë
49 ¥Ç¥£¥¹¥¯¥ê¥×¥¿¤òÀ¸À®¤¹¤ë¡£
50 ¤³¤ÎÊýË¡¤Ï¥·¥°¥Ê¥ë¥Ï¥ó¥É¥é¤ä
52 ¤òÍѤ¤¤ëÊýË¡¤ÎÂå¤ï¤ê¤È¤Ê¤ë¤â¤Î¤Ç¤¢¤ê¡¢¤³¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ò
56 ¤Ç´Æ»ë¤Ç¤¤ë¤È¤¤¤¦ÍøÅÀ¤¬¤¢¤ë¡£
60 .\"O argument specifies the set of signals that the caller
61 .\"O wishes to accept via the file descriptor.
62 .\"O This argument is a signal set whose contents can be initialized
63 .\"O using the macros described in
64 .\"O .BR sigsetops (3).
66 °ú¤¿ô¤Ë¤Ï¡¢¸Æ¤Ó½Ð¤·¸µ¤¬¤³¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿·Ðͳ¤Ç¼õ¤±ÉÕ¤±¤¿¤¤
67 ¥·¥°¥Ê¥ë½¸¹ç¤ò»ØÄꤹ¤ë¡£¤³¤Î°ú¤¿ô¤Ç»ØÄꤹ¤ë¥·¥°¥Ê¥ë½¸¹ç¤ÎÆâÍƤϡ¢
69 ¤ÇÀâÌÀ¤µ¤ì¤Æ¤¤¤ë¥Þ¥¯¥í¤ò»È¤Ã¤Æ½é´ü²½¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£
70 .\"O Normally, the set of signals to be received via the
71 .\"O file descriptor should be blocked using
72 .\"O .BR sigprocmask (2),
73 .\"O to prevent the signals being handled according to their default
75 Ä̾¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿·Ðͳ¤Ç¼õ¿®¤¹¤ë¥·¥°¥Ê¥ë½¸¹ç¤Ï¡¢
76 ¤½¤Î¥·¥°¥Ê¥ë¤¬¥Ç¥Õ¥©¥ë¥È¤ÎÇÛÁ÷ÊýË¡¤Ë´ð¤¤¤Æ½èÍý¤µ¤ì¤ë¤Î¤òËɤ°¤¿¤á¤Ë¡¢
78 ¤ò»È¤Ã¤Æ¥Ö¥í¥Ã¥¯¤·¤Æ¤ª¤¯¤Ù¤¤Ç¤¢¤ë¡£
79 .\"O It is not possible to receive
83 .\"O signals via a signalfd file descriptor;
84 .\"O these signals are silently ignored if specified in
90 ¤ò signalfd ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿·Ðͳ¤Ç¼õ¿®¤¹¤ë¤³¤È¤Ï¤Ç¤¤Ê¤¤¡£
93 ¤Ç»ØÄꤵ¤ì¤¿¾ì¹ç¤Ë¤ÏÌۤäÆ̵»ë¤µ¤ì¤ë¡£
98 .\"O then the call creates a new file descriptor and associates the
99 .\"O signal set specified in
101 .\"O with that descriptor.
105 .\"O then it must specify a valid existing signalfd file descriptor, and
107 .\"O is used to replace the signal set associated with that descriptor.
109 °ú¤¿ô¤¬ \-1 ¤Î¾ì¹ç¡¢
111 ¤Ï¿·¤·¤¤¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤òÀ¸À®¤·¡¢
113 ¤Ç»ØÄꤵ¤ì¤¿¥·¥°¥Ê¥ë½¸¹ç¤ò¤½¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ë´ØÏ¢ÉÕ¤±¤ë¡£
115 °ú¤¿ô¤¬ \-1 °Ê³°¤Î¾ì¹ç¡¢
117 ¤Ë¤Ï͸ú¤Ê´û¸¤Î signalfd ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ò»ØÄꤷ¤Ê¤±¤ì¤Ð¤Ê¤é¤º¡¢
118 ¤½¤Î¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ë´ØÏ¢ÉÕ¤±¤é¤ì¤Æ¤¤¤ë¥·¥°¥Ê¥ë½¸¹ç¤Ï
120 ¤ò»È¤Ã¤ÆÃÖ¤´¹¤¨¤é¤ì¤ë¡£
122 .\"O Starting with Linux 2.6.27, the following values may be bitwise ORed in
124 .\"O to change the behaviour of
125 .\"O .BR signalfd ():
126 Linux 2.6.27 °Ê¹ß¤Ç¤Ï¡¢
127 °Ê²¼¤ÎÃͤΤ¤¤¯¤Ä¤«¤ò¥Ó¥Ã¥Èñ°Ì¤ÎÏÀÍýÏ (OR) ¤Ç»ØÄꤹ¤ë¤³¤È¤Ç¡¢
129 ¤Î¿¶Éñ¤¤¤òÊѹ¹¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£
134 .\"O file status flag on the new open file description.
135 .\"O Using this flag saves extra calls to
137 .\"O to achieve the same result.
138 ¿·¤·¤¯À¸À®¤µ¤ì¤ë¥ª¡¼¥×¥ó¥Õ¥¡¥¤¥ëµ½Ò (open file description) ¤Î
140 ¥Õ¥¡¥¤¥ë¥¹¥Æ¡¼¥¿¥¹¥Õ¥é¥°¤ò¥»¥Ã¥È¤¹¤ë¡£
141 ¤³¤Î¥Õ¥é¥°¤ò»È¤¦¤³¤È¤Ç¡¢
145 ¤òÄɲäǸƤӽФ¹É¬Íפ¬¤Ê¤¯¤Ê¤ë¡£
148 .\"O Set the close-on-exec
149 .\"O .RB ( FD_CLOEXEC )
150 .\"O flag on the new file descriptor.
151 .\"O See the description of the
155 .\"O for reasons why this may be useful.
156 ¿·¤·¤¤¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ËÂФ·¤Æ
160 ¤³¤Î¥Õ¥é¥°¤¬Ìò¤ËΩ¤ÄÍýͳ¤Ë¤Ä¤¤¤Æ¤Ï¡¢
164 ¥Õ¥é¥°¤ÎÀâÌÀ¤ò»²¾È¤Î¤³¤È¡£
166 .\"O In Linux up to version 2.6.26, the
168 .\"O argument is unused, and must be specified as zero.
169 ¥Ð¡¼¥¸¥ç¥ó 2.6.26 °ÊÁ°¤Î Linux ¤Ç¤Ï¡¢
171 °ú¤¿ô¤Ï̤»ÈÍѤǤ¢¤ê¡¢0 ¤ò»ØÄꤷ¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
174 .\"O returns a file descriptor that supports the following operations:
176 ¤¬ÊÖ¤¹¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ï°Ê²¼¤ÎÁàºî¤ò¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤ë¡£
179 .\"O If one or more of the signals specified in
181 .\"O is pending for the process, then the buffer supplied to
183 .\"O is used to return one or more
184 .\"O .I signalfd_siginfo
185 .\"O structures (see below) that describe the signals.
188 .\"O returns information for as many signals as are pending and will
189 .\"O fit in the supplied buffer.
190 .\"O The buffer must be at least
191 .\"O .I "sizeof(struct signalfd_siginfo)"
193 .\"O The return value of the
195 .\"O is the total number of bytes read.
197 ¤Ë»ØÄꤵ¤ì¤Æ¤¤¤ë¥·¥°¥Ê¥ë¤Î¤¦¤Á°ì¤Ä°Ê¾å¤¬¤½¤Î¥×¥í¥»¥¹¤ËÂФ·¤Æ
198 ½èÍýÂÔ¤Á (pending) ¤Ç¤¢¤ì¤Ð¡¢¤½¤ì¤é¤Î¥·¥°¥Ê¥ë¤Î¾ðÊó¤¬
200 ¤ËÅϤµ¤ì¤¿¥Ð¥Ã¥Õ¥¡¤ò»È¤Ã¤Æ¡¢
202 ¹½Â¤ÂΤ˳ÊǼ¤µ¤ì¤ÆÊÖ¤µ¤ì¤ë¡£
204 ¤Ï¡¢¥Ð¥Ã¥Õ¥¡¤Ë³ÊǼ²Äǽ¤ÊÈϰϤǤǤ¤ë¤À¤±Â¿¤¯¤Î½èÍýÂÔ¤Á¤Î¥·¥°¥Ê¥ë¤Ë
207 .I "sizeof(struct signalfd_siginfo)"
208 ¥Ð¥¤¥È¤ÎÂ礤µ¤¬¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
210 ¤ÎÊÖ¤êÃͤÏÆɤ߽Фµ¤ì¤¿¥È¡¼¥¿¥ë¤Î¥Ð¥¤¥È¿ô¤Ç¤¢¤ë¡£
212 .\"O As a consequence of the
214 .\"O the signals are consumed,
215 .\"O so that they are no longer pending for the process
216 .\"O (i.e., will not be caught by signal handlers,
217 .\"O and cannot be accepted using
218 .\"O .BR sigwaitinfo (2)).
220 ¤¬¹Ô¤ï¤ì¤¿·ë²Ì¡¢¥·¥°¥Ê¥ë¤Ï¾ÃÈñ¤µ¤ì¡¢
221 ¤³¤ì¤é¤Î¥·¥°¥Ê¥ë¤Ï¤½¤Î¥×¥í¥»¥¹¤ËÂФ·¤Æ¤Ï½èÍýÂÔ¤Á¤Ç¤Ï¤Ê¤¯¤Ê¤ë
222 (¤Ä¤Þ¤ê¡¢¥·¥°¥Ê¥ë¥Ï¥ó¥É¥é¤ÇÊ᪤µ¤ì¤ë¤³¤È¤â¤Ê¤¯¡¢
224 ¤ò»È¤Ã¤Æ¼õ¤±¼è¤ë¤³¤È¤â¤Ç¤¤Ê¤¯¤Ê¤ë)¡£
226 .\"O If none of the signals in
228 .\"O is pending for the process, then the
230 .\"O either blocks until one of the signals in
232 .\"O is generated for the process,
233 .\"O or fails with the error
235 .\"O if the file descriptor has been made nonblocking.
237 ¤Ë»ØÄꤵ¤ì¤Æ¤¤¤ë¥·¥°¥Ê¥ë¤¬¤½¤Î¥×¥í¥»¥¹¤ËÂФ·¤Æ°ì¤Ä¤â½èÍýÂÔ¤Á¤Ç¤Ê¤±¤ì¤Ð¡¢
241 ¤Ç»ØÄꤵ¤ì¤¿¥·¥°¥Ê¥ë¤Î¤¦¤Á¤¤¤º¤ì¤«°ì¤Ä¤¬¤½¤Î¥×¥í¥»¥¹¤ËÂФ·¤ÆȯÀ¸¤¹¤ë¤Þ¤Ç
242 Ää»ß (block) ¤¹¤ë¡¢¤â¤·¤¯¤Ï¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤¬ÈóÄä»ß (nonblocking)
243 ¤ËÀßÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ï¥¨¥é¡¼
247 .\"O .BR poll "(2), " select "(2) (and similar)"
248 .BR poll "(2), " select "(2) (¤ÈƱÍͤÎÁàºî)"
249 .\"O The file descriptor is readable
257 .\"O if one or more of the signals in
259 .\"O is pending for the process.
261 ¤Ë»ØÄꤵ¤ì¤¿¥·¥°¥Ê¥ë¤Î¤¦¤Á°ì¤Ä°Ê¾å¤¬¤½¤Î¥×¥í¥»¥¹¤ËÂФ·¤Æ½èÍýÂÔ¤Á¤Ç¤¢¤ì¤Ð¡¢
262 ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ÏÆɤ߽Ф·²Äǽ¤È¤Ê¤ë
272 .\"O The signalfd file descriptor also supports the other file-descriptor
273 .\"O multiplexing APIs:
274 .\"O .BR pselect (2),
278 signalfd ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ï¡¢¤³¤ì°Ê³°¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿
286 .\"O When the file descriptor is no longer required it should be closed.
287 .\"O When all file descriptors associated with the same signalfd object
288 .\"O have been closed, the resources for object are freed by the kernel.
289 ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤¬¤½¤ì°Ê¹ß¤ÏɬÍפʤ¯¤Ê¤Ã¤¿ºÝ¤Ë¤Ï¡¢¥¯¥í¡¼¥º¤¹¤Ù¤¤Ç¤¢¤ë¡£
290 Ʊ¤¸ signalfd ¥ª¥Ö¥¸¥§¥¯¥È¤Ë´ØÏ¢ÉÕ¤±¤é¤ì¤¿¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤¬Á´¤Æ
291 ¥¯¥í¡¼¥º¤µ¤ì¤ë¤È¡¢¤½¤Î¥ª¥Ö¥¸¥§¥¯¥ÈÍѤλñ¸»¤¬¥«¡¼¥Í¥ë¤Ë¤è¤ê²òÊü¤µ¤ì¤ë¡£
292 .\"O .SS The signalfd_siginfo structure
293 .SS signalfd_siginfo ¹½Â¤ÂÎ
294 .\"O The format of the
295 .\"O .I signalfd_siginfo
296 .\"O structure(s) returned by
298 .\"O from a signalfd file descriptor is as follows:
299 signalfd ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤«¤é¤Î
303 ¹½Â¤ÂΤΥե©¡¼¥Þ¥Ã¥È¤Ï°Ê²¼¤ÎÄ̤ê¤Ç¤¢¤ë¡£
307 struct signalfd_siginfo {
308 .\"O uint32_t ssi_signo; /* Signal number */
309 .\"O int32_t ssi_errno; /* Error number (unused) */
310 .\"O int32_t ssi_code; /* Signal code */
311 .\"O uint32_t ssi_pid; /* PID of sender */
312 .\"O uint32_t ssi_uid; /* Real UID of sender */
313 .\"O int32_t ssi_fd; /* File descriptor (SIGIO) */
314 .\"O uint32_t ssi_tid; /* Kernel timer ID (POSIX timers)
315 .\"O uint32_t ssi_band; /* Band event (SIGIO) */
316 .\"O uint32_t ssi_overrun; /* POSIX timer overrun count */
317 .\"O uint32_t ssi_trapno; /* Trap number that caused signal */
318 .\"O .\" ssi_trapno is unused on most arches
319 .\"O int32_t ssi_status; /* Exit status or signal (SIGCHLD) */
320 .\"O int32_t ssi_int; /* Integer sent by sigqueue(3) */
321 .\"O uint64_t ssi_ptr; /* Pointer sent by sigqueue(3) */
322 .\"O uint64_t ssi_utime; /* User CPU time consumed (SIGCHLD) */
323 .\"O uint64_t ssi_stime; /* System CPU time consumed (SIGCHLD) */
324 .\"O uint64_t ssi_addr; /* Address that generated signal
325 .\"O (for hardware-generated signals) */
326 .\"O uint8_t pad[\fIX\fP]; /* Pad size to 128 bytes (allow for
327 .\"O additional fields in the future) */
328 struct signalfd_siginfo {
329 uint32_t ssi_signo; /* ¥·¥°¥Ê¥ëÈÖ¹æ */
330 int32_t ssi_errno; /* ¥¨¥é¡¼ÈÖ¹æ (̤»ÈÍÑ) */
331 int32_t ssi_code; /* ¥·¥°¥Ê¥ë¥³¡¼¥É */
332 uint32_t ssi_pid; /* Á÷¿®¸µ¤Î PID */
333 uint32_t ssi_uid; /* Á÷¿®¸µ¤Î¼Â UID */
334 int32_t ssi_fd; /* ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿ (SIGIO) */
335 uint32_t ssi_tid; /* ¥«¡¼¥Í¥ë¥¿¥¤¥Þ ID (POSIX ¥¿¥¤¥Þ)
336 uint32_t ssi_band; /* Band ¥¤¥Ù¥ó¥È (SIGIO) */
337 uint32_t ssi_overrun; /* POSIX ¥¿¥¤¥Þ¤Î¥ª¡¼¥Ð¡¼¥é¥ó²ó¿ô */
338 uint32_t ssi_trapno; /* ¥·¥°¥Ê¥ë¤Î¸¶°ø¤È¤Ê¤Ã¤¿¥È¥é¥Ã¥×ÈÖ¹æ */
339 .\" ¤Û¤È¤ó¤É¤Î¥¢¡¼¥¥Æ¥¯¥Á¥ã¤Ç ssi_trapno ¤Ï̤»ÈÍÑ
340 int32_t ssi_status; /* ½ªÎ»¥¹¥Æ¡¼¥¿¥¹¤«¥·¥°¥Ê¥ë (SIGCHLD) */
341 int32_t ssi_int; /* sigqueue(3) ¤«¤éÁ÷¤é¤ì¤¿À°¿ô */
342 uint64_t ssi_ptr; /* sigqueue(3) ¤«¤éÁ÷¤é¤ì¤¿¥Ý¥¤¥ó¥¿ */
343 uint64_t ssi_utime; /* ¾ÃÈñ¤·¤¿¥æ¡¼¥¶ CPU »þ´Ö (SIGCHLD) */
344 uint64_t ssi_stime; /* ¾ÃÈñ¤·¤¿¥·¥¹¥Æ¥à CPU »þ´Ö (SIGCHLD) */
345 uint64_t ssi_addr; /* ¥·¥°¥Ê¥ë¤òÀ¸À®¤·¤¿¥¢¥É¥ì¥¹
346 (¥Ï¡¼¥É¥¦¥§¥¢¤¬À¸À®¤·¤¿¥·¥°¥Ê¥ë¤Î¾ì¹ç) */
347 uint8_t pad[\fIX\fP]; /* pad ¤ÎÂ礤µ¤Ï 128 ¥Ð¥¤¥È
348 (¾Íè¤Î¥Õ¥£¡¼¥ë¥ÉÄɲÃÍѤξì½ê¤Î³ÎÊÝ) */
353 .\"O Each of the fields in this structure
354 .\"O is analogous to the similarly named field in the
359 .\"O structure is described in
360 .\"O .BR sigaction (2).
362 ¹½Â¤ÂΤγƥե£¡¼¥ë¥É¤Ï¡¢
364 ¹½Â¤ÂΤÎƱ¤¸¤è¤¦¤Ê̾Á°¤Î¥Õ¥£¡¼¥ë¥É¤ÈƱÍͤǤ¢¤ë¡£
369 .\"O Not all fields in the returned
370 .\"O .I signalfd_siginfo
371 .\"O structure will be valid for a specific signal;
372 .\"O the set of valid fields can be determined from the value returned in the
375 .\"O This field is the analog of the
379 .\"O .BR sigaction (2)
383 ¹½Â¤ÂΤÎÁ´¤Æ¤Î¥Õ¥£¡¼¥ë¥É¤¬¤¢¤ë¥·¥°¥Ê¥ë¤ËÂФ·¤Æ͸ú¤Ê¤ï¤±¤Ç¤Ï¤Ê¤¤¡£
384 ¤É¤Î¥Õ¥£¡¼¥ë¥É¤¬Í¸ú¤«¤Ï¡¢
386 ¥Õ¥£¡¼¥ë¥É¤ÇÊÖ¤µ¤ì¤ëÃͤ«¤éȽÄꤹ¤ë¤³¤È¤¬¤Ç¤¤ë¡£
391 ¥Õ¥£¡¼¥ë¥É¤ÈƱÍͤǤ¢¤ë¡£¾ÜºÙ¤Ï
394 .\"O .SS fork(2) semantics
398 .\"O the child inherits a copy of the signalfd file descriptor.
401 .\"O from the file descriptor in the child will return information
402 .\"O about signals queued to the child.
404 ¤¬¹Ô¤ï¤ì¤ë¤È¡¢»Ò¥×¥í¥»¥¹¤Ï signalfd ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Î¥³¥Ô¡¼¤ò
406 »Ò¥×¥í¥»¥¹¤Ç¤³¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤«¤é
408 ¤ò¹Ô¤¦¤È¡¢»Ò¥×¥í¥»¥¹¤ËÂФ¹¤ë¥¥å¡¼¤ËÆþ¤Ã¤Æ¤¤¤ë¥·¥°¥Ê¥ë¤Ë´Ø¤¹¤ë
410 .\"O .SS execve(2) semantics
411 .SS execve(2) ¤Ç¤Î°·¤¤
412 .\"O Just like any other file descriptor,
413 .\"O a signalfd file descriptor remains open across an
415 .\"O unless it has been marked for close-on-exec (see
417 .\"O Any signals that were available for reading before the
419 .\"O remain available to the newly loaded program.
420 .\"O (This is analogous to traditional signal semantics,
421 .\"O where a blocked signal that is pending remains pending across an
422 .\"O .BR execve (2).)
423 ¾¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ÈÁ´¤¯Æ±Íͤˡ¢
424 signalfd ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤â
426 ¤ÎÁ°¸å¤Ç¥ª¡¼¥×¥ó¤µ¤ì¤¿¤Þ¤Þ¤È¤Ê¤ë¡£Ã¢¤·¡¢¤½¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ë
427 close-on-exec ¤Î¥Þ¡¼¥¯
429 »²¾È) ¤¬ÉÕ¤¤¤Æ¤¤¤ë¾ì¹ç¤Ï¥¯¥í¡¼¥º¤µ¤ì¤ë¡£
431 ¤ÎÁ°¤ËÆɤ߽Ф·²Äǽ¤È¤Ê¤Ã¤Æ¤¤¤¿Á´¤Æ¤Î¥·¥°¥Ê¥ë¤Ï¿·¤·¤¯µ¯Æ°¤µ¤ì¤¿¥×¥í¥°¥é¥à
432 ¤Ç¤â°ú¤Â³¤Æɤ߽Ф·²Äǽ¤Ç¤¢¤ë
433 (¤³¤ì¤ÏÅÁÅýŪ¤Ê¥·¥°¥Ê¥ë¤Î°·¤¤¤ÈƱ¤¸¤Ç¤¢¤ê¡¢
434 ½èÍýÂÔ¤Á¤Î¥Ö¥í¥Ã¥¯¤µ¤ì¤¿¥·¥°¥Ê¥ë¤Ï
436 ¤ÎÁ°¸å¤Ç½èÍýÂÔ¤Á¤Î¤Þ¤Þ¤È¤Ê¤ë)¡£
437 .\"O .SS Thread semantics
439 .\"O The semantics of signalfd file descriptors in a multithreaded program
440 .\"O mirror the standard semantics for signals.
442 .\"O when a thread reads from a signalfd file descriptor,
443 .\"O it will read the signals that are directed to the thread
444 .\"O itself and the signals that are directed to the process
445 .\"O (i.e., the entire thread group).
446 .\"O (A thread will not be able to read signals that are directed
447 .\"O to other threads in the process.)
448 ¥Þ¥ë¥Á¥¹¥ì¥Ã¥É¥×¥í¥°¥é¥à¤Ë¤ª¤±¤ë signalfd ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Î°·¤¤¤Ï
449 ¥·¥°¥Ê¥ë¤Îɸ½àŪ¤Ê°·¤¤¤ÈÁ´¤¯Æ±¤¸¤Ç¤¢¤ë¡£
450 ¸À¤¤´¹¤¨¤ë¤È¡¢¤¢¤ë¥¹¥ì¥Ã¥É¤¬ signalfd ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤«¤é
451 Æɤ߽Ф·¤ò¹Ô¤¦¤È¡¢¤½¤Î¥¹¥ì¥Ã¥É¼«¿È°¸¤Æ¤Î¥·¥°¥Ê¥ë¤È¥×¥í¥»¥¹ (¤¹¤Ê¤ï¤Á
452 ¥¹¥ì¥Ã¥É¥°¥ë¡¼¥×Á´ÂÎ) °¸¤Æ¤Î¥·¥°¥Ê¥ë¤¬Æɤ߽Фµ¤ì¤ë¡£
453 (¥¹¥ì¥Ã¥É¤ÏƱ¤¸¥×¥í¥»¥¹¤Î¾¤Î¥¹¥ì¥Ã¥É°¸¤Æ¤Î¥·¥°¥Ê¥ë¤òÆɤ߽Ф¹¤³¤È¤Ï¤Ç¤¤Ê¤¤¡£)
454 .\"O .SH "RETURN VALUE"
458 .\"O returns a signalfd file descriptor;
459 .\"O this is either a new file descriptor (if
465 .\"O was a valid signalfd file descriptor.
466 .\"O On error, \-1 is returned and
468 .\"O is set to indicate the error.
471 ¤Ï signalfd ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤òÊÖ¤¹¡£
472 ÊÖ¤µ¤ì¤ë¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ï¡¢
474 ¤¬ \-1 ¤Î¾ì¹ç¤Ï¿·µ¬¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ç¤¢¤ê¡¢
476 ¤¬Í¸ú¤Ê signalfd ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤À¤Ã¤¿¾ì¹ç¤Ï
479 ¥¨¥é¡¼¤Î¾ì¹ç¡¢\-1 ¤òÊÖ¤·¡¢
481 ¤Ë¥¨¥é¡¼¤ò¼¨¤¹ÃͤòÀßÄꤹ¤ë¡£
488 .\"O file descriptor is not a valid file descriptor.
489 ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿
491 ¤¬Í¸ú¤Ê¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ç¤Ê¤¤¡£
495 .\"O is not a valid signalfd file descriptor.
497 ¤¬Í¸ú¤Ê signalfd ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ç¤Ï¤Ê¤¤¡£
500 .\" argument is not equal to
501 .\" .IR sizeof(sigset_t) ;
506 .\"O or, in Linux 2.6.26 or earlier,
511 Linux 2.6.26 °ÊÁ°¤Ç¤Ï¡¢
516 .\"O The per-process limit of open file descriptors has been reached.
517 ¥ª¡¼¥×¥óºÑ¤ß¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Î¿ô¤¬¥×¥í¥»¥¹¤¢¤¿¤ê¤Î¾å¸Â¤Ë
521 .\"O The system-wide limit on the total number of open files has been
523 ¥ª¡¼¥×¥óºÑ¤ß¤Î¥Õ¥¡¥¤¥ëÁí¿ô¤¬¥·¥¹¥Æ¥àÁ´ÂΤξå¸Â¤Ë㤷¤Æ¤¤¤¿¡£
526 .\"O Could not mount (internal) anonymous inode device.
527 (¥«¡¼¥Í¥ëÆâ¤Î) ̵̾ inode ¥Ç¥Ð¥¤¥¹¤ò¥Þ¥¦¥ó¥È¤Ç¤¤Ê¤«¤Ã¤¿¡£
530 .\"O There was insufficient memory to create a new signalfd file descriptor.
531 ¿·¤·¤¤ signalfd ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤òÀ¸À®¤¹¤ë¤Î¤Ë½½Ê¬¤Ê¥á¥â¥ê¤¬¤Ê¤«¤Ã¤¿¡£
535 .\"O is available on Linux since kernel 2.6.22.
536 .\"O Working support is provided in glibc since version 2.8.
538 ¤Ï¥«¡¼¥Í¥ë 2.6.22 °Ê¹ß¤Î Linux ¤ÇÍøÍѲÄǽ¤Ç¤¢¤ë¡£
539 Àµ¤·¤¯Æ°ºî¤¹¤ë glibc ¦¤Î¥µ¥Ý¡¼¥È¤Ï¥Ð¡¼¥¸¥ç¥ó 2.8 °Ê¹ß¤ÇÄ󶡤µ¤ì¤Æ¤¤¤ë¡£
540 .\" signalfd() is in glibc 2.7, but reportedly does not build
542 .\"O .BR signalfd4 ()
543 .\"O system call (see NOTES) is available on Linux since kernel 2.6.27.
545 ¥·¥¹¥Æ¥à¥³¡¼¥ë (¡ÖÃí°Õ¡×»²¾È) ¤Ï
546 ¥«¡¼¥Í¥ë 2.6.27 °Ê¹ß¤Î Linux ¤ÇÍøÍѲÄǽ¤Ç¤¢¤ë¡£
547 .\"O .SH CONFORMING TO
551 .\"O .BR signalfd4 ()
552 .\"O are Linux-specific.
556 ¤Ï Linux ¸ÇͤǤ¢¤ë¡£
559 .\"O The underlying Linux system call requires an additional argument,
560 .\"O .IR "size_t sizemask" ,
561 .\"O which specifies the size of the
566 .\"O wrapper function does not include this argument,
567 .\"O since it provides the required value for the underlying system call.
568 ¼ÂºÝ¤Î Linux ¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ç¤Ï
570 ¤È¤¤¤¦°ú¤¿ô¤¬ÄɲäÇɬÍפǤ¢¤ë¡£¤³¤Î°ú¤¿ô¤Ç
575 ¥é¥Ã¥Ñ¡¼´Ø¿ô¤Ë¤Ï¤³¤Î°ú¤¿ô¤Ï´Þ¤Þ¤ì¤º¡¢
576 ¥é¥Ã¥Ñ¡¼´Ø¿ô¤¬É¬ÍפÊÃͤò·×»»¤·¤ÆÆâÉô¤Ç¸Æ¤Ó½Ð¤¹¥·¥¹¥Æ¥à¥³¡¼¥ë¤ËÄ󶡤¹¤ë¡£
578 .\"O A process can create multiple signalfd file descriptors.
579 .\"O This makes it possible to accept different signals
580 .\"O on different file descriptors.
581 .\"O (This may be useful if monitoring the file descriptors using
586 .\"O the arrival of different signals will make different descriptors ready.)
587 .\"O If a signal appears in the
589 .\"O of more than one of the file descriptors, then occurrences
590 .\"O of that signal can be read (once) from any one of the descriptors.
591 °ì¤Ä¤Î¥×¥í¥»¥¹¤ÏÊ£¿ô¤Î signalfd ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤òÀ¸À®¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£
592 ¤³¤ì¤Ë¤è¤ê¡¢°Û¤Ê¤ë¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ç°Û¤Ê¤ë¥·¥°¥Ê¥ë¤ò¼õ¤±¼è¤ë¤³¤È¤¬
597 ¤ò»È¤Ã¤Æ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ò´Æ»ë¤¹¤ë¾ì¹ç¤ËÍÍѤ«¤â¤·¤ì¤Ê¤¤¡£
598 °Û¤Ê¤ë¥·¥°¥Ê¥ë¤¬ÅþÃ夹¤ë¤È¡¢°Û¤Ê¤ë¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤¬ÍøÍѲÄǽ¤Ë
600 °ì¤Ä¤Î¥·¥°¥Ê¥ë¤¬Æó¤Ä°Ê¾å¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Î
602 ¤Ë´Þ¤Þ¤ì¤Æ¤¤¤ë¾ì¹ç¡¢¤½¤Î¥·¥°¥Ê¥ë¤ÎȯÀ¸¤Ï¤½¤Î¥·¥°¥Ê¥ë¤ò
604 ¤Ë´Þ¤à¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Î¤¦¤Á¤¤¤º¤ì¤«°ì¤Ä¤«¤éÆɤ߽Ф¹¤³¤È¤¬¤Ç¤¤ë¡£
605 .\"O .SS Underlying Linux system calls
606 .SH ²¼Áؤˤ¢¤ë Linux ¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë
607 .\"O There are two underlying Linux system calls:
609 .\"O and the more recent
610 .\"O .BR signalfd4 ().
611 .\"O The former system call does not implement a
614 .\"O The latter system call implements the
616 .\"O values described above.
617 ²¼Áؤˤ¢¤ë Linux ¥·¥¹¥Æ¥à¥³¡¼¥ë¤ÏÆó¼ïÎढ¤ê¡¢
625 °ú¤¿ô¤ò¼ÂÁõ¤·¤Æ¤¤¤Ê¤¤¡£
630 .\"O Starting with glibc 2.9, the
632 .\"O wrapper function will use
633 .\"O .BR signalfd4 ()
634 .\"O where it is available.
639 ¤¬ÍøÍѲÄǽ¤Ç¤¢¤ì¤Ð¡¢¤³¤ì¤ò»ÈÍѤ¹¤ë¡£
642 .\"O In kernels before 2.6.25, the
646 .\"O fields are not filled in with the data accompanying a signal sent by
647 .\"O .BR sigqueue (3).
648 ¥«¡¼¥Í¥ë 2.6.25 ¤è¤êÁ°¤Ç¤Ï¡¢
650 ¤Ë¤è¤êÁ÷¿®¤µ¤ì¤¿¥·¥°¥Ê¥ë¤È°ì½ï¤ËÅϤµ¤ì¤ë¥Ç¡¼¥¿¤Ç¤Ï¡¢¥Õ¥£¡¼¥ë¥É
655 .\" The fix also was put into 2.6.24.5
658 .\"O The program below accepts the signals
662 .\"O via a signalfd file descriptor.
663 .\"O The program terminates after accepting a
666 .\"O The following shell session demonstrates the use of the program:
667 ²¼µ¤Î¥×¥í¥°¥é¥à¤Ï¡¢¥·¥°¥Ê¥ë
671 ¤ò signalfd ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿·Ðͳ¤Ç¼õ¿®¤¹¤ë¡£
674 ¼õ¿®¸å¤Ë¥×¥í¥°¥é¥à¤Ï½ªÎ»¤¹¤ë¡£
675 °Ê²¼¤Ë¼¨¤¹¥·¥§¥ë¥»¥Ã¥·¥ç¥ó¤Ë¤³¤Î¥×¥í¥°¥é¥à¤Î»È¤¤Êý¤ò¼¨¤¹¡£
679 .RB "$" " ./signalfd_demo"
680 .BR "^C" " # Control\-C generates SIGINT"
684 \fB^\\\fP # Control\-\\ generates SIGQUIT
689 .\"O .SS Program source
690 .SS ¥×¥í¥°¥é¥à¤Î¥½¡¼¥¹
693 #include <sys/signalfd.h>
699 #define handle_error(msg) \\
700 do { perror(msg); exit(EXIT_FAILURE); } while (0)
703 main(int argc, char *argv[])
707 struct signalfd_siginfo fdsi;
711 sigaddset(&mask, SIGINT);
712 sigaddset(&mask, SIGQUIT);
714 /* Block signals so that they aren\(aqt handled
715 according to their default dispositions */
717 if (sigprocmask(SIG_BLOCK, &mask, NULL) == \-1)
718 handle_error("sigprocmask");
720 sfd = signalfd(\-1, &mask, 0);
722 handle_error("signalfd");
725 s = read(sfd, &fdsi, sizeof(struct signalfd_siginfo));
726 if (s != sizeof(struct signalfd_siginfo))
727 handle_error("read");
729 if (fdsi.ssi_signo == SIGINT) {
730 printf("Got SIGINT\\n");
731 } else if (fdsi.ssi_signo == SIGQUIT) {
732 printf("Got SIGQUIT\\n");
735 printf("Read unexpected signal\\n");
749 .BR timerfd_create (2),