OSDN Git Service

(split) LDP: Update original to LDP v3.41.
[linuxjm/LDP_man-pages.git] / original / man2 / sigwaitinfo.2
1 .\" Copyright (c) 2002 Michael Kerrisk <mtk.manpages@gmail.com>
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein.  The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .TH SIGWAITINFO 2 2012-05-02 "Linux" "Linux Programmer's Manual"
24 .SH NAME
25 sigwaitinfo, sigtimedwait \- synchronously wait for queued signals
26 .SH SYNOPSIS
27 .nf
28 .B #include <signal.h>
29 .sp
30 .BI "int sigwaitinfo(const sigset_t *" set ", siginfo_t *" info ");"
31 .sp
32 .BI "int sigtimedwait(const sigset_t *" set ", siginfo_t *" info ", "
33 .BI "                 const struct timespec *" timeout ");"
34 .fi
35 .sp
36 .in -4n
37 Feature Test Macro Requirements for glibc (see
38 .BR feature_test_macros (7)):
39 .in
40 .sp
41 .BR sigwaitinfo (),
42 .BR sigtimedwait ():
43 _POSIX_C_SOURCE\ >=\ 199309L
44 .SH DESCRIPTION
45 .BR sigwaitinfo ()
46 suspends execution of the calling thread until one of the signals in
47 .I set
48 is delivered.
49 (If one of the signals in
50 .I set
51 is already pending for the calling thread,
52 .BR sigwaitinfo ()
53 will return immediately with information about that signal.)
54
55 .BR sigwaitinfo ()
56 removes the delivered signal from the set of pending
57 signals and returns the signal number as its function result.
58 If the
59 .I info
60 argument is not NULL,
61 then it returns a structure of type
62 .I siginfo_t
63 (see
64 .BR sigaction (2))
65 containing information about the signal.
66 .PP
67 Signals returned via
68 .BR sigwaitinfo ()
69 are delivered in the usual order; see
70 .BR signal (7)
71 for further details.
72 .PP
73 .BR sigtimedwait ()
74 operates in exactly the same way as
75 .BR sigwaitinfo ()
76 except that it has an additional argument,
77 .IR timeout ,
78 which specifies a minimum interval for which
79 the thread is suspended waiting for a signal.
80 (This interval will be rounded up to the system clock granularity,
81 and kernel scheduling delays mean that the interval
82 may overrun by a small amount.)
83 This argument is of the following type:
84 .sp
85 .in +4n
86 .nf
87 struct timespec {
88     long    tv_sec;         /* seconds */
89     long    tv_nsec;        /* nanoseconds */
90 }
91 .fi
92 .in
93 .sp
94 If both fields of this structure are specified as 0, a poll is performed:
95 .BR sigtimedwait ()
96 returns immediately, either with information about a signal that
97 was pending for the caller, or with an error
98 if none of the signals in
99 .I set
100 was pending.
101 .SH "RETURN VALUE"
102 On success, both
103 .BR sigwaitinfo ()
104 and
105 .BR sigtimedwait ()
106 return a signal number (i.e., a value greater than zero).
107 On failure both calls return \-1, with
108 .I errno
109 set to indicate the error.
110 .SH ERRORS
111 .TP
112 .B EAGAIN
113 No signal in
114 .I set
115 was delivered within the
116 .I timeout
117 period specified to
118 .BR sigtimedwait ().
119 .TP
120 .B EINTR
121 The wait was interrupted by a signal handler; see
122 .BR signal (7).
123 (This handler was for a signal other than one of those in
124 .IR set .)
125 .TP
126 .B EINVAL
127 .I timeout
128 was invalid.
129 .SH "CONFORMING TO"
130 POSIX.1-2001.
131 .SH NOTES
132 In normal usage, the calling program blocks the signals in
133 .I set
134 via a prior call to
135 .BR sigprocmask (2)
136 (so that the default disposition for these signals does not occur if they
137 are delivered between successive calls to
138 .BR sigwaitinfo ()
139 or
140 .BR sigtimedwait ())
141 and does not establish handlers for these signals.
142 In a multithreaded program,
143 the signal should be blocked in all threads to prevent
144 the signal being delivered to a thread other than the one calling
145 .BR sigwaitinfo ()
146 or
147 .BR sigtimedwait ()).
148
149 The set of signals that is pending for a given thread is the
150 union of the set of signals that is pending specifically for that thread
151 and the set of signals that is pending for the process as a whole (see
152 .BR signal (7)).
153
154 Attempts to wait for
155 .B SIGKILL
156 and
157 .B SIGSTOP
158 are silently ignored.
159
160 If multiple threads of a process are blocked
161 waiting for the same signal(s) in
162 .BR sigwaitinfo ()
163 or
164 .BR sigtimedwait (),
165 then exactly one of the threads will actually receive the
166 signal if it is delivered to the process as a whole;
167 which of the threads receives the signal is indeterminate.
168
169 POSIX leaves the meaning of a NULL value for the
170 .I timeout
171 argument of
172 .BR sigtimedwait ()
173 unspecified, permitting the possibility that this has the same meaning
174 as a call to
175 .BR sigwaitinfo (),
176 and indeed this is what is done on Linux.
177
178 On Linux,
179 .BR sigwaitinfo ()
180 is a library function implemented on top of
181 .BR sigtimedwait ().
182 .SH "SEE ALSO"
183 .BR kill (2),
184 .BR sigaction (2),
185 .BR signal (2),
186 .BR signalfd (2),
187 .BR sigpending (2),
188 .BR sigprocmask (2),
189 .BR sigqueue (3),
190 .BR sigsetops (3),
191 .BR sigwait (3),
192 .BR signal (7),
193 .BR time (7)