File: signalfd.2

package info (click to toggle)
manpages-ja 0.5.0.0.20100315-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 21,156 kB
  • ctags: 1
  • sloc: sh: 13,935; perl: 157; makefile: 114
file content (453 lines) | stat: -rw-r--r-- 12,694 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
.\" Copyright (C) 2008 Michael Kerrisk <mtk.manpages@gmail.com>
.\" starting from a version by Davide Libenzi <davidel@xmailserver.org>
.\"
.\" This program is free software; you can redistribute it and/or modify
.\" it under the terms of the GNU General Public License as published by
.\" the Free Software Foundation; either version 2 of the License, or
.\" (at your option) any later version.
.\"
.\" This program is distributed in the hope that it will be useful,
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
.\" GNU General Public License for more details.
.\"
.\" You should have received a copy of the GNU General Public License
.\" along with this program; if not, write to the Free Software
.\" Foundation, Inc., 59 Temple Place, Suite 330, Boston,
.\" MA  02111-1307  USA
.\"
.\" Japanese Version Copyright (c) 2008  Akihiro MOTOKI
.\"         all rights reserved.
.\" Translated 2008-04-06, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.79
.\" Updated 2008-11-10, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.13
.\" Updated 2009-02-23, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.18
.\" 
.TH SIGNALFD 2 2009-01-13 Linux "Linux Programmer's Manual"
.SH ̾
signalfd \- ʥդѤΥեǥץ
.SH 
.B #include <sys/signalfd.h>
.sp
.BI "int signalfd(int " fd ", const sigset_t *" mask ", int " flags );
.SH 
.BR signalfd ()
ϡƤӽФƤΥʥդ뤿˻Ѥե
ǥץ롣
ˡϥʥϥɥ
.BR sigwaitinfo (2)
ѤˡȤʤΤǤꡢΥեǥץ
.BR select (2),
.BR poll (2),
.BR epoll (7)
ǴƻǤȤ롣

.I mask
ˤϡƤӽФΥեǥץͳǼդ
ʥ뽸ꤹ롣ΰǻꤹ륷ʥ뽸Ƥϡ
.BR sigsetops (3)
ƤޥȤäƽ뤳ȤǤ롣
̾եǥץͳǼ륷ʥ뽸ϡ
Υʥ뤬ǥեȤˡ˴𤤤ƽΤɤˡ
.BR sigprocmask (2)
Ȥäƥ֥åƤ٤Ǥ롣
ʥ
.B SIGKILL

.B SIGSTOP
 signalfd եǥץͳǼ뤳ȤϤǤʤ
Υʥ뤬
.I mask
ǻꤵ줿ˤۤä̵뤵롣

.I fd
 \-1 ξ硢
.BR signalfd ()
Ͽեǥץ
.I mask
ǻꤵ줿ʥ뽸򤽤Υեǥץ˴Ϣդ롣
.I fd
 \-1 ʳξ硢
.I fd
ˤͭʴ¸ signalfd եǥץꤷʤФʤ餺
Υǥץ˴ϢդƤ륷ʥ뽸
.I mask
Ȥä֤롣

Linux 2.6.27 ʹߤǤϡ
ʲͤΤĤӥåñ̤ (OR) ǻꤹ뤳Ȥǡ
.BR signalfd ()
ο񤤤ѹ뤳ȤǤ롣
.TP 14
.B SFD_NONBLOCK
륪ץե뵭 (open file description) 
.B O_NONBLOCK
ե륹ơե饰򥻥åȤ롣
Υե饰ȤȤǡ
.B O_NONBLOCK
򥻥åȤ뤿
.BR fcntl (2)
ɲäǸƤӽФɬפʤʤ롣
.TP
.B SFD_CLOEXEC
եǥץФ
close-on-exec
.RB ( FD_CLOEXEC )
ե饰򥻥åȤ롣
Υե饰ΩͳˤĤƤϡ
.BR open (2)

.B O_CLOEXEC
ե饰򻲾ȤΤȡ
.PP
С 2.6.26  Linux Ǥϡ
.I flags
̤ѤǤꡢ0 ꤷʤФʤʤ

.BR signalfd ()
֤եǥץϰʲ򥵥ݡȤƤ롣
.TP
.BR read (2)
.I mask
˻ꤵƤ륷ʥΤİʾ夬ΥץФ
Ԥ (pending) ǤСΥʥξ
.BR read (2)
Ϥ줿ХåեȤäơ
.I signalfd_siginfo
¤Τ˳Ǽ֤롣
.BR read (2)
ϡХåե˳ǼǽϰϤǤǤ¿νԤΥʥ
ĤƤξ֤
ХåեϺǤ
.I "sizeof(struct signalfd_siginfo)"
ХȤ礭ʤФʤʤ
.BR read (2)
֤ͤɤ߽Ф줿ȡΥХȿǤ롣
.IP
.BR read (2)
Ԥ줿̡ʥϾ񤵤졢
ΥʥϤΥץФƤϽԤǤϤʤʤ
(Ĥޤꡢʥϥɥª뤳Ȥʤ
.BR sigwaitinfo (2)
ȤäƼ뤳ȤǤʤʤ)
.IP
.I mask
˻ꤵƤ륷ʥ뤬ΥץФưĤԤǤʤС
.BR read (2)
ϡ
.I mask
ǻꤵ줿ʥΤ줫ĤΥץФȯޤ
 (block) 롢⤷ϥեǥץ (non-blocking)
ꤵƤϥ顼
.B EAGAIN
ǼԤ롣
.TP
.BR poll "(2), " select "(2) (Ʊͤ)"
.I mask
˻ꤵ줿ʥΤİʾ夬ΥץФƽԤǤС
եǥץɤ߽ФǽȤʤ
.RB ( select (2)

.I readfds

.BR poll (2)

.B POLLIN
ե饰)
.IP
signalfd եǥץϡʳΥեǥץ
¿ API Ǥ
.BR pselect (2),
.BR ppoll (2),
.BR epoll (7)
⥵ݡȤƤ롣
.TP
.BR close (2)
եǥץʹߤɬפʤʤäݤˤϡ٤Ǥ롣
Ʊ signalfd ֥Ȥ˴Ϣդ줿եǥץ
ȡΥ֥Ѥλ񸻤ͥˤ롣
.SS signalfd_siginfo ¤
signalfd եǥץ
.BR read (2)
֤
.I signalfd_siginfo
¤ΤΥեޥåȤϰʲ̤Ǥ롣
.in +4n
.nf

struct signalfd_siginfo {
struct signalfd_siginfo {
    uint32_t ssi_signo;   /* ʥֹ */
    int32_t  ssi_errno;   /* 顼ֹ (̤) */
    int32_t  ssi_code;    /* ʥ륳 */
    uint32_t ssi_pid;     /*  PID */
    uint32_t ssi_uid;     /* μ UID */
    int32_t  ssi_fd;      /* եǥץ (SIGIO) */
    uint32_t ssi_tid;     /* ͥ륿 ID (POSIX )
    uint32_t ssi_band;    /* Band ٥ (SIGIO) */
    uint32_t ssi_overrun; /* POSIX ޤΥС */
    uint32_t ssi_trapno;  /* ʥθȤʤäȥåֹ */
.\" ۤȤɤΥƥ ssi_trapno ̤
    int32_t  ssi_status;  /* λơʥ (SIGCHLD) */
    int32_t  ssi_int;     /* sigqueue(2) 줿 */
    uint64_t ssi_ptr;     /* sigqueue(2) 줿ݥ */
    uint64_t ssi_utime;   /* 񤷤桼 CPU  (SIGCHLD) */
    uint64_t ssi_stime;   /* 񤷤ƥ CPU  (SIGCHLD) */
    uint64_t ssi_addr;    /* ʥɥ쥹
                             (ϡɥʥξ) */
    uint8_t  pad[\fIX\fP];      /* pad 礭 128 Х
                             (ΥեɲѤξγ) */
};

.fi
.in
.I signalfd_siginfo
¤Τγƥեɤϡ
.I siginfo_t
¤ΤƱ褦̾ΥեɤƱͤǤ롣
.I siginfo_t
¤ΤˤĤƤ
.BR sigaction (2)
֤줿
.I signalfd_siginfo
¤ΤƤΥեɤ륷ʥФͭʤ櫓ǤϤʤ
ɤΥեɤͭϡ
.I ssi_code
եɤ֤ͤȽꤹ뤳ȤǤ롣
Υեɤ
.I siginfo_t

.I si_code
եɤƱͤǤ롣ܺ٤
.BR sigaction (2)
򻲾ȡ
.SS fork(2) Ǥΰ
.BR fork (2)
Ԥȡҥץ signalfd եǥץΥԡ
Ѿ롣
ҥץǤΥեǥץ
.BR read (2)
ԤȡҥץФ륭塼äƤ륷ʥ˴ؤ
֤롣
.SS execve(2) Ǥΰ
¾ΥեǥץƱͤˡ
signalfd եǥץ
.BR execve (2)
ǥץ󤵤줿ޤޤȤʤ롣âΥեǥץ
close-on-exec Υޡ
.RB ( fcntl (2)
) դƤϥ롣
.BR execve (2)
ɤ߽ФǽȤʤäƤƤΥʥϿư줿ץ
Ǥ³ɤ߽ФǽǤ
(ŪʥʥΰƱǤꡢ
ԤΥ֥å줿ʥ
.BR execve (2)
ǽԤΤޤޤȤʤ)
.SS åɤǤΰ
ޥåɥץˤ signalfd եǥץΰ
ʥɸŪʰƱǤ롣
ȡ륹åɤ signalfd եǥץ
ɤ߽ФԤȡΥåɼȰƤΥʥȥץ (ʤ
åɥ롼) ƤΥʥ뤬ɤ߽Ф롣
(åɤƱץ¾ΥåɰƤΥʥɤ߽ФȤϤǤʤ)
.SH ֤
ȡ
.BR signalfd ()
 signalfd եǥץ֤
֤եǥץϡ
.IR fd
 \-1 ξϿΥեǥץǤꡢ
.I fd
ͭ signalfd եǥץä
.I fd
ȤǤ롣
顼ξ硢\-1 ֤
.I errno
˥顼򼨤ͤꤹ롣
.SH 顼
.TP
.B EBADF
եǥץ
.I fd
ͭʥեǥץǤʤ
.TP
.B EINVAL
.I fd
ͭ signalfd եǥץǤϤʤ
.\" or, the
.\" .I sizemask
.\" argument is not equal to
.\" .IR sizeof(sigset_t) ;
.TP
.B EINVAL
.I flags
̵
Linux 2.6.26 Ǥϡ
.I flags
 0 ʳ͡
.TP
.B EMFILE
ץѤߤΥեǥץοץξ¤
ãƤ
.TP
.B ENFILE
ץѤߤΥեƥΤξ¤ãƤ
.TP
.B ENODEV
(ͥ) ̵̾ inode ǥХޥȤǤʤä
.TP
.B ENOMEM
 signalfd եǥץΤ˽ʬʥ꤬ʤä
.SH С
.BR signalfd ()
ϥͥ 2.6.22 ʹߤ Linux ѲǽǤ롣
ư glibc ¦ΥݡȤϥС 2.8 ʹߤ󶡤Ƥ롣
.\" signalfd() is in glibc 2.7, but reportedly does not build
.BR signalfd4 ()
ƥॳ (ա׻) 
ͥ 2.6.27 ʹߤ Linux ѲǽǤ롣
.SH 
.BR signalfd ()

.BR signalfd4 ()
 Linux ͭǤ롣
.SH 
ºݤ Linux ΥƥॳǤ
.I "size_t sizemask"
ȤɲäɬפǤ롣ΰ
.I mask
Υꤹ롣
glibc 
.BR signalfd ()
åѡؿˤϤΰϴޤޤ줺
åѡؿɬפͤ׻ǸƤӽФƥॳ󶡤롣

ĤΥץʣ signalfd եǥץ뤳ȤǤ롣
ˤꡢۤʤեǥץǰۤʤ륷ʥ뤳Ȥ
Ǥ (εǽ
.BR select (2),
.BR poll (2),
.BR epoll (7)
Ȥäƥեǥץƻ뤹ͭѤ⤷ʤ
ۤʤ륷ʥ뤬夹ȡۤʤեǥץѲǽ
ʤ뤫)
ĤΥʥ뤬İʾΥեǥץ
.I mask
˴ޤޤƤ硢ΥʥȯϤΥʥ
.I mask
˴ޤեǥץΤ줫Ĥɤ߽ФȤǤ롣
.SH ؤˤ Linux Υƥॳ
ؤˤ Linux ƥॳढꡢ
.BR signalfd ()
ȡäȿ
.BR signalfd4 ()
Ǥ롣
.BR signalfd ()

.I flags
Ƥʤ
.BR signalfd4 ()
ǤϾ嵭ͤ
.I flags
Ƥ롣
glibc 2.9 ʹߤǤϡ
.BR signalfd ()
Υåѡؿϡ
.BR signalfd4 ()
ѲǽǤСѤ롣
.SH Х
ͥ 2.6.25 Ǥϡ
.BR sigqueue (2)
ˤ줿ʥȰϤǡǤϡե
.I ssi_ptr

.I ssi_int
ꤵʤ
.\" The fix also was put into 2.6.24.5
.SH 
Υץϡʥ
.B SIGINT

.B SIGQUIT
 signalfd եǥץͳǼ롣
ʥ
.B SIGQUIT
˥ץϽλ롣
ʲ˼륻åˤΥץλȤ򼨤
.in +4n
.nf

.RB "$" " ./signalfd_demo"
.BR "^C" "                   # Control\-C generates SIGINT"
Got SIGINT
.B ^C
Got SIGINT
\fB^\\\fP                    # Control\-\\ generates SIGQUIT
Got SIGQUIT
$
.fi
.in
.SS ץΥ
\&
.nf
#include <sys/signalfd.h>
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>

#define handle_error(msg) \\
    do { perror(msg); exit(EXIT_FAILURE); } while (0)

int
main(int argc, char *argv[])
{
    sigset_t mask;
    int sfd;
    struct signalfd_siginfo fdsi;
    ssize_t s;

    sigemptyset(&mask);
    sigaddset(&mask, SIGINT);
    sigaddset(&mask, SIGQUIT);

    /* Block signals so that they aren\(aqt handled
       according to their default dispositions */

    if (sigprocmask(SIG_BLOCK, &mask, NULL) == \-1)
        handle_error("sigprocmask");

    sfd = signalfd(\-1, &mask, 0);
    if (sfd == \-1)
        handle_error("signalfd");

    for (;;) {
        s = read(sfd, &fdsi, sizeof(struct signalfd_siginfo));
        if (s != sizeof(struct signalfd_siginfo))
            handle_error("read");

        if (fdsi.ssi_signo == SIGINT) {
            printf("Got SIGINT\\n");
        } else if (fdsi.ssi_signo == SIGQUIT) {
            printf("Got SIGQUIT\\n");
            exit(EXIT_SUCCESS);
        } else {
            printf("Read unexpected signal\\n");
        }
    }
}
.fi
.SH Ϣ
.BR eventfd (2),
.BR poll (2),
.BR read (2),
.BR select (2),
.BR sigaction (2),
.BR sigprocmask (2),
.BR sigwaitinfo (2),
.BR timerfd_create (2),
.BR sigsetops (3),
.BR sigwait (3),
.BR epoll (7),
.BR signal (7)