OSDN Git Service

cb23766f58e8aad3f6cab015f185cc8ef9bb0882
[linuxjm/LDP_man-pages.git] / draft / man2 / signalfd.2
1 .\" Copyright (C) 2008 Michael Kerrisk <mtk.manpages@gmail.com>
2 .\" starting from a version by Davide Libenzi <davidel@xmailserver.org>
3 .\"
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.
8 .\"
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.
13 .\"
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,
17 .\" MA  02111-1307  USA
18 .\"
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
24 .\" 
25 .TH SIGNALFD 2 2009-01-13 Linux "Linux Programmer's Manual"
26 .\"O .SH NAME
27 .SH 名前
28 .\"O signalfd \- create a file descriptor for accepting signals
29 signalfd \- シグナル受け付け用のファイルディスクリプタを生成する
30 .\"O .SH SYNOPSIS
31 .SH 書式
32 .B #include <sys/signalfd.h>
33 .sp
34 .BI "int signalfd(int " fd ", const sigset_t *" mask ", int " flags );
35 .\"O .SH DESCRIPTION
36 .SH 説明
37 .\"O .BR signalfd ()
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
43 .\"O .BR select (2),
44 .\"O .BR poll (2),
45 .\"O and
46 .\"O .BR epoll (7).
47 .BR signalfd ()
48 は、呼び出し元宛てのシグナルを受け付けるために使用されるファイル
49 ディスクリプタを生成する。
50 この方法はシグナルハンドラや
51 .BR sigwaitinfo (2)
52 を用いる方法の代わりとなるものであり、このファイルディスクリプタを
53 .BR select (2),
54 .BR poll (2),
55 .BR epoll (7)
56 で監視できるという利点がある。
57
58 .\"O The
59 .\"O .I mask
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).
65 .I mask
66 引き数には、呼び出し元がこのファイルディスクリプタ経由で受け付けたい
67 シグナル集合を指定する。この引き数で指定するシグナル集合の内容は、
68 .BR sigsetops (3)
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
74 .\"O dispositions.
75 通常、ファイルディスクリプタ経由で受信するシグナル集合は、
76 そのシグナルがデフォルトの配送方法に基いて処理されるのを防ぐために、
77 .BR sigprocmask (2)
78 を使ってブロックしておくべきである。
79 .\"O It is not possible to receive
80 .\"O .B SIGKILL
81 .\"O or
82 .\"O .B SIGSTOP
83 .\"O signals via a signalfd file descriptor;
84 .\"O these signals are silently ignored if specified in
85 .\"O .IR mask .
86 シグナル
87 .B SIGKILL
88
89 .B SIGSTOP
90 を signalfd ファイルディスクリプタ経由で受信することはできない。
91 これらのシグナルが
92 .I mask
93 で指定された場合には黙って無視される。
94
95 .\"O If the
96 .\"O .I fd
97 .\"O argument is \-1,
98 .\"O then the call creates a new file descriptor and associates the
99 .\"O signal set specified in
100 .\"O .I mask
101 .\"O with that descriptor.
102 .\"O If
103 .\"O .I fd
104 .\"O is not \-1,
105 .\"O then it must specify a valid existing signalfd file descriptor, and
106 .\"O .I mask
107 .\"O is used to replace the signal set associated with that descriptor.
108 .I fd
109 引き数が \-1 の場合、
110 .BR signalfd ()
111 は新しいファイルディスクリプタを生成し、
112 .I mask
113 で指定されたシグナル集合をそのファイルディスクリプタに関連付ける。
114 .I fd
115 引き数が \-1 以外の場合、
116 .I fd
117 には有効な既存の signalfd ファイルディスクリプタを指定しなければならず、
118 そのディスクリプタに関連付けられているシグナル集合は
119 .I mask
120 を使って置き換えられる。
121
122 .\"O Starting with Linux 2.6.27, the following values may be bitwise ORed in
123 .\"O .IR flags
124 .\"O to change the behaviour of
125 .\"O .BR signalfd ():
126 Linux 2.6.27 以降では、
127 以下の値のいくつかをビット単位の論理和 (OR) で指定することで、
128 .BR signalfd ()
129 の振舞いを変更することができる。
130 .TP 14
131 .B SFD_NONBLOCK
132 .\"O Set the
133 .\"O .BR O_NONBLOCK
134 .\"O file status flag on the new open file description.
135 .\"O Using this flag saves extra calls to
136 .\"O .BR fcntl (2)
137 .\"O to achieve the same result.
138 新しく生成されるオープンファイル記述 (open file description) の
139 .B O_NONBLOCK
140 ファイルステータスフラグをセットする。
141 このフラグを使うことで、
142 .B O_NONBLOCK
143 をセットするために
144 .BR fcntl (2)
145 を追加で呼び出す必要がなくなる。
146 .TP
147 .B SFD_CLOEXEC
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
152 .\"O .B O_CLOEXEC
153 .\"O flag in
154 .\"O .BR open (2)
155 .\"O for reasons why this may be useful.
156 新しいファイルディスクリプタに対して
157 close-on-exec
158 .RB ( FD_CLOEXEC )
159 フラグをセットする。
160 このフラグが役に立つ理由については、
161 .BR open (2)
162
163 .B O_CLOEXEC
164 フラグの説明を参照のこと。
165 .PP
166 .\"O In Linux up to version 2.6.26, the
167 .\"O .I flags
168 .\"O argument is unused, and must be specified as zero.
169 バージョン 2.6.26 以前の Linux では、
170 .I flags
171 引き数は未使用であり、0 を指定しなければならない。
172
173 .\"O .BR signalfd ()
174 .\"O returns a file descriptor that supports the following operations:
175 .BR signalfd ()
176 が返すファイルディスクリプタは以下の操作をサポートしている。
177 .TP
178 .BR read (2)
179 .\"O If one or more of the signals specified in
180 .\"O .I mask
181 .\"O is pending for the process, then the buffer supplied to
182 .\"O .BR read (2)
183 .\"O is used to return one or more
184 .\"O .I signalfd_siginfo
185 .\"O structures (see below) that describe the signals.
186 .\"O The
187 .\"O .BR read (2)
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)"
192 .\"O bytes.
193 .\"O The return value of the
194 .\"O .BR read (2)
195 .\"O is the total number of bytes read.
196 .I mask
197 に指定されているシグナルのうち一つ以上がそのプロセスに対して
198 処理待ち (pending) であれば、それらのシグナルの情報が
199 .BR read (2)
200 に渡されたバッファを使って、
201 .I signalfd_siginfo
202 構造体に格納されて返される。
203 .BR read (2)
204 は、バッファに格納可能な範囲でできるだけ多くの処理待ちのシグナルに
205 ついての情報を返す。
206 バッファは最低でも
207 .I "sizeof(struct signalfd_siginfo)"
208 バイトの大きさがなければならない。
209 .BR read (2)
210 の返り値は読み出されたトータルのバイト数である。
211 .IP
212 .\"O As a consequence of the
213 .\"O .BR read (2),
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)).
219 .BR read (2)
220 が行われた結果、シグナルは消費され、
221 これらのシグナルはそのプロセスに対しては処理待ちではなくなる
222 (つまり、シグナルハンドラで捕捉されることもなく、
223 .BR sigwaitinfo (2)
224 を使って受け取ることもできなくなる)。
225 .IP
226 .\"O If none of the signals in
227 .\"O .I mask
228 .\"O is pending for the process, then the
229 .\"O .BR read (2)
230 .\"O either blocks until one of the signals in
231 .\"O .I mask
232 .\"O is generated for the process,
233 .\"O or fails with the error
234 .\"O .B EAGAIN
235 .\"O if the file descriptor has been made nonblocking.
236 .I mask
237 に指定されているシグナルがそのプロセスに対して一つも処理待ちでなければ、
238 .BR read (2)
239 は、
240 .I mask
241 で指定されたシグナルのうちいずれか一つがそのプロセスに対して発生するまで
242 停止 (block) する、もしくはファイルディスクリプタが非停止 (nonblocking)
243 に設定されている場合はエラー
244 .B EAGAIN
245 で失敗する。
246 .TP
247 .\"O .BR poll "(2), " select "(2) (and similar)"
248 .BR poll "(2), " select "(2) (と同様の操作)"
249 .\"O The file descriptor is readable
250 .\"O (the
251 .\"O .BR select (2)
252 .\"O .I readfds
253 .\"O argument; the
254 .\"O .BR poll (2)
255 .\"O .B POLLIN
256 .\"O flag)
257 .\"O if one or more of the signals in
258 .\"O .I mask
259 .\"O is pending for the process.
260 .I mask
261 に指定されたシグナルのうち一つ以上がそのプロセスに対して処理待ちであれば、
262 ファイルディスクリプタは読み出し可能となる
263 .RB ( select (2)
264
265 .I readfds
266 引き数や
267 .BR poll (2)
268
269 .B POLLIN
270 フラグ)。
271 .IP
272 .\"O The signalfd file descriptor also supports the other file-descriptor
273 .\"O multiplexing APIs:
274 .\"O .BR pselect (2),
275 .\"O .BR ppoll (2),
276 .\"O and
277 .\"O .BR epoll (7).
278 signalfd ファイルディスクリプタは、これ以外のファイルディスクリプタ
279 多重 API である
280 .BR pselect (2),
281 .BR ppoll (2),
282 .BR epoll (7)
283 もサポートしている。
284 .TP
285 .BR close (2)
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
297 .\"O .BR read (2)s
298 .\"O from a signalfd file descriptor is as follows:
299 signalfd ファイルディスクリプタからの
300 .BR read (2)
301 で返される
302 .I signalfd_siginfo
303 構造体のフォーマットは以下の通りである。
304 .in +4n
305 .nf
306
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                              (将来のフィールド追加用の場所の確保) */
349 };
350
351 .fi
352 .in
353 .\"O Each of the fields in this structure
354 .\"O is analogous to the similarly named field in the
355 .\"O .I siginfo_t
356 .\"O structure.
357 .\"O The
358 .\"O .I siginfo_t
359 .\"O structure is described in
360 .\"O .BR sigaction (2).
361 .I signalfd_siginfo
362 構造体の各フィールドは、
363 .I siginfo_t
364 構造体の同じような名前のフィールドと同様である。
365 .I siginfo_t
366 構造体については
367 .BR sigaction (2)
368 に説明がある。
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
373 .\"O .I ssi_code
374 .\"O field.
375 .\"O This field is the analog of the
376 .\"O .I siginfo_t
377 .\"O .I si_code
378 .\"O field; see
379 .\"O .BR sigaction (2)
380 .\"O for details.
381 返された
382 .I signalfd_siginfo
383 構造体の全てのフィールドがあるシグナルに対して有効なわけではない。
384 どのフィールドが有効かは、
385 .I ssi_code
386 フィールドで返される値から判定することができる。
387 このフィールドは
388 .I siginfo_t
389
390 .I si_code
391 フィールドと同様である。詳細は
392 .BR sigaction (2)
393 を参照。
394 .\"O .SS fork(2) semantics
395 .SS fork(2) での扱い
396 .\"O After a
397 .\"O .BR fork (2),
398 .\"O the child inherits a copy of the signalfd file descriptor.
399 .\"O A
400 .\"O .BR read (2)
401 .\"O from the file descriptor in the child will return information
402 .\"O about signals queued to the child.
403 .BR fork (2)
404 が行われると、子プロセスは signalfd ファイルディスクリプタのコピーを
405 継承する。
406 子プロセスでこのファイルディスクリプタから
407 .BR read (2)
408 を行うと、子プロセスに対するキューに入っているシグナルに関する
409 情報が返される。
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
414 .\"O .BR execve (2),
415 .\"O unless it has been marked for close-on-exec (see
416 .\"O .BR fcntl (2)).
417 .\"O Any signals that were available for reading before the
418 .\"O .BR execve (2)
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 ファイルディスクリプタも
425 .BR execve (2)
426 の前後でオープンされたままとなる。但し、そのファイルディスクリプタに
427 close-on-exec のマーク
428 .RB ( fcntl (2)
429 参照) が付いている場合はクローズされる。
430 .BR execve (2)
431 の前に読み出し可能となっていた全てのシグナルは新しく起動されたプログラム
432 でも引き続き読み出し可能である
433 (これは伝統的なシグナルの扱いと同じであり、
434 処理待ちのブロックされたシグナルは
435 .BR execve (2)
436 の前後で処理待ちのままとなる)。
437 .\"O .SS Thread semantics
438 .SS スレッドでの扱い
439 .\"O The semantics of signalfd file descriptors in a multithreaded program
440 .\"O mirror the standard semantics for signals.
441 .\"O In other words,
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"
455 .SH 返り値
456 .\"O On success,
457 .\"O .BR signalfd ()
458 .\"O returns a signalfd file descriptor;
459 .\"O this is either a new file descriptor (if
460 .\"O .I fd
461 .\"O was \-1), or
462 .\"O .I fd
463 .\"O if
464 .\"O .I fd
465 .\"O was a valid signalfd file descriptor.
466 .\"O On error, \-1 is returned and
467 .\"O .I errno
468 .\"O is set to indicate the error.
469 成功すると、
470 .BR signalfd ()
471 は signalfd ファイルディスクリプタを返す。
472 返されるファイルディスクリプタは、
473 .IR fd
474 が \-1 の場合は新規のファイルディスクリプタであり、
475 .I fd
476 が有効な signalfd ファイルディスクリプタだった場合は
477 .I fd
478 自身である。
479 エラーの場合、\-1 を返し、
480 .I errno
481 にエラーを示す値を設定する。
482 .\"O .SH ERRORS
483 .SH エラー
484 .TP
485 .B EBADF
486 .\"O The
487 .\"O .I fd
488 .\"O file descriptor is not a valid file descriptor.
489 ファイルディスクリプタ
490 .I fd
491 が有効なファイルディスクリプタでない。
492 .TP
493 .B EINVAL
494 .\"O .I fd
495 .\"O is not a valid signalfd file descriptor.
496 .I fd
497 が有効な signalfd ファイルディスクリプタではない。
498 .\" or, the
499 .\" .I sizemask
500 .\" argument is not equal to
501 .\" .IR sizeof(sigset_t) ;
502 .TP
503 .B EINVAL
504 .\"O .I flags
505 .\"O is invalid;
506 .\"O or, in Linux 2.6.26 or earlier,
507 .\"O .I flags
508 .\"O is nonzero.
509 .I flags
510 が無効。
511 Linux 2.6.26 以前では、
512 .I flags
513 が 0 以外の値。
514 .TP
515 .B EMFILE
516 .\"O The per-process limit of open file descriptors has been reached.
517 オープン済みのファイルディスクリプタの数がプロセスあたりの上限に
518 達していた。
519 .TP
520 .B ENFILE
521 .\"O The system-wide limit on the total number of open files has been
522 .\"O reached.
523 オープン済みのファイル総数がシステム全体の上限に達していた。
524 .TP
525 .B ENODEV
526 .\"O Could not mount (internal) anonymous inode device.
527 (カーネル内の) 無名 inode デバイスをマウントできなかった。
528 .TP
529 .B ENOMEM
530 .\"O There was insufficient memory to create a new signalfd file descriptor.
531 新しい signalfd ファイルディスクリプタを生成するのに十分なメモリがなかった。
532 .\"O .SH VERSIONS
533 .SH バージョン
534 .\"O .BR signalfd ()
535 .\"O is available on Linux since kernel 2.6.22.
536 .\"O Working support is provided in glibc since version 2.8.
537 .BR signalfd ()
538 はカーネル 2.6.22 以降の Linux で利用可能である。
539 正しく動作する glibc 側のサポートはバージョン 2.8 以降で提供されている。
540 .\" signalfd() is in glibc 2.7, but reportedly does not build
541 .\"O The
542 .\"O .BR signalfd4 ()
543 .\"O system call (see NOTES) is available on Linux since kernel 2.6.27.
544 .BR signalfd4 ()
545 システムコール (「注意」参照) は
546 カーネル 2.6.27 以降の Linux で利用可能である。
547 .\"O .SH CONFORMING TO
548 .SH 準拠
549 .\"O .BR signalfd ()
550 .\"O and
551 .\"O .BR signalfd4 ()
552 .\"O are Linux-specific.
553 .BR signalfd ()
554
555 .BR signalfd4 ()
556 は Linux 固有である。
557 .\"O .SH NOTES
558 .SH 注意
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
562 .\"O .I mask
563 .\"O argument.
564 .\"O The glibc
565 .\"O .BR signalfd ()
566 .\"O wrapper function does not include this argument,
567 .\"O since it provides the required value for the underlying system call.
568 実際の Linux のシステムコールでは
569 .I "size_t sizemask"
570 という引き数が追加で必要である。この引き数で
571 .I mask
572 のサイズを指定する。
573 glibc の
574 .BR signalfd ()
575 ラッパー関数にはこの引き数は含まれず、
576 ラッパー関数が必要な値を計算して内部で呼び出すシステムコールに提供する。
577
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
582 .\"O .BR select (2),
583 .\"O .BR poll (2),
584 .\"O or
585 .\"O .BR epoll (7):
586 .\"O the arrival of different signals will make different descriptors ready.)
587 .\"O If a signal appears in the
588 .\"O .I mask
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 これにより、異なるファイルディスクリプタで異なるシグナルを受け取ることが
593 できる (この機能は
594 .BR select (2),
595 .BR poll (2),
596 .BR epoll (7)
597 を使ってファイルディスクリプタを監視する場合に有用かもしれない。
598 異なるシグナルが到着すると、異なるファイルディスクリプタが利用可能に
599 なるからだ)。
600 一つのシグナルが二つ以上のファイルディスクリプタの
601 .I mask
602 に含まれている場合、そのシグナルの発生はそのシグナルを
603 .I mask
604 に含むファイルディスクリプタのうちいずれか一つから読み出すことができる。
605 .\"O .SS Underlying Linux system calls
606 .SH 下層にある Linux のシステムコール
607 .\"O There are two underlying Linux system calls:
608 .\"O .BR signalfd ()
609 .\"O and the more recent
610 .\"O .BR signalfd4 ().
611 .\"O The former system call does not implement a
612 .\"O .I flags
613 .\"O argument.
614 .\"O The latter system call implements the
615 .\"O .I flags
616 .\"O values described above.
617 下層にある Linux システムコールは二種類あり、
618 .BR signalfd ()
619 と、もっと新しい
620 .BR signalfd4 ()
621 である。
622 .BR signalfd ()
623
624 .I flags
625 引き数を実装していない。
626 .BR signalfd4 ()
627 では上記の値の
628 .I flags
629 が実装されている。
630 .\"O Starting with glibc 2.9, the
631 .\"O .BR signalfd ()
632 .\"O wrapper function will use
633 .\"O .BR signalfd4 ()
634 .\"O where it is available.
635 glibc 2.9 以降では、
636 .BR signalfd ()
637 のラッパー関数は、
638 .BR signalfd4 ()
639 が利用可能であれば、これを使用する。
640 .\"O .SH BUGS
641 .SH バグ
642 .\"O In kernels before 2.6.25, the
643 .\"O .I ssi_ptr
644 .\"O and
645 .\"O .I ssi_int
646 .\"O fields are not filled in with the data accompanying a signal sent by
647 .\"O .BR sigqueue (3).
648 カーネル 2.6.25 より前では、
649 .BR sigqueue (3)
650 により送信されたシグナルと一緒に渡されるデータでは、フィールド
651 .I ssi_ptr
652
653 .I ssi_int
654 は設定されない。
655 .\" The fix also was put into 2.6.24.5
656 .\"O .SH EXAMPLE
657 .SH 例
658 .\"O The program below accepts the signals
659 .\"O .B SIGINT
660 .\"O and
661 .\"O .B SIGQUIT
662 .\"O via a signalfd file descriptor.
663 .\"O The program terminates after accepting a
664 .\"O .B SIGQUIT
665 .\"O signal.
666 .\"O The following shell session demonstrates the use of the program:
667 下記のプログラムは、シグナル
668 .B SIGINT
669
670 .B SIGQUIT
671 を signalfd ファイルディスクリプタ経由で受信する。
672 シグナル
673 .B SIGQUIT
674 受信後にプログラムは終了する。
675 以下に示すシェルセッションにこのプログラムの使い方を示す。
676 .in +4n
677 .nf
678
679 .RB "$" " ./signalfd_demo"
680 .BR "^C" "                   # Control\-C generates SIGINT"
681 Got SIGINT
682 .B ^C
683 Got SIGINT
684 \fB^\\\fP                    # Control\-\\ generates SIGQUIT
685 Got SIGQUIT
686 $
687 .fi
688 .in
689 .\"O .SS Program source
690 .SS プログラムのソース
691 \&
692 .nf
693 #include <sys/signalfd.h>
694 #include <signal.h>
695 #include <unistd.h>
696 #include <stdlib.h>
697 #include <stdio.h>
698
699 #define handle_error(msg) \\
700     do { perror(msg); exit(EXIT_FAILURE); } while (0)
701
702 int
703 main(int argc, char *argv[])
704 {
705     sigset_t mask;
706     int sfd;
707     struct signalfd_siginfo fdsi;
708     ssize_t s;
709
710     sigemptyset(&mask);
711     sigaddset(&mask, SIGINT);
712     sigaddset(&mask, SIGQUIT);
713
714     /* Block signals so that they aren\(aqt handled
715        according to their default dispositions */
716
717     if (sigprocmask(SIG_BLOCK, &mask, NULL) == \-1)
718         handle_error("sigprocmask");
719
720     sfd = signalfd(\-1, &mask, 0);
721     if (sfd == \-1)
722         handle_error("signalfd");
723
724     for (;;) {
725         s = read(sfd, &fdsi, sizeof(struct signalfd_siginfo));
726         if (s != sizeof(struct signalfd_siginfo))
727             handle_error("read");
728
729         if (fdsi.ssi_signo == SIGINT) {
730             printf("Got SIGINT\\n");
731         } else if (fdsi.ssi_signo == SIGQUIT) {
732             printf("Got SIGQUIT\\n");
733             exit(EXIT_SUCCESS);
734         } else {
735             printf("Read unexpected signal\\n");
736         }
737     }
738 }
739 .fi
740 .\"O .SH "SEE ALSO"
741 .SH 関連項目
742 .BR eventfd (2),
743 .BR poll (2),
744 .BR read (2),
745 .BR select (2),
746 .BR sigaction (2),
747 .BR sigprocmask (2),
748 .BR sigwaitinfo (2),
749 .BR timerfd_create (2),
750 .BR sigsetops (3),
751 .BR sigwait (3),
752 .BR epoll (7),
753 .BR signal (7)