📄 pthread_sigmask.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta name="generator" content="HTML Tidy, see www.w3.org"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 --><!-- Copyright (c) 2001-2004 IEEE and The Open Group, All Rights Reserved --><title>pthread_sigmask</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="pthread_sigmask"></a> <a name="tag_03_573"></a><!-- pthread_sigmask --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2004 Edition<br>Copyright © 2001-2004 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_573_01"></a>NAME</h4><blockquote>pthread_sigmask, sigprocmask - examine and change blocked signals</blockquote><h4><a name="tag_03_573_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><p><code><tt>#include <<a href="../basedefs/signal.h.html">signal.h</a>><br><br></tt></code></p><div class="box"><code><tt><sup>[<a href="javascript:open_code('THR')">THR</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> int pthread_sigmask(int</tt> <i>how</i><tt>, const sigset_t *restrict</tt> <i>set</i><tt>,<br> sigset_t *restrict</tt> <i>oset</i><tt>);<br> <img src="../images/opt-end.gif" alt="[Option End]" border="0"></tt></code></div><div class="box"><code><tt><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> int sigprocmask(int</tt> <i>how</i><tt>, const sigset_t *restrict</tt> <i>set</i><tt>,<br> sigset_t *restrict</tt> <i>oset</i><tt>); <img src="../images/opt-end.gif" alt="[Option End]"border="0"></tt></code></div><tt><br></tt></blockquote><h4><a name="tag_03_573_03"></a>DESCRIPTION</h4><blockquote><p><sup>[<a href="javascript:open_code('THR')">THR</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">The <i>pthread_sigmask</i>() function shall examine or change (or both) the calling thread's signal mask, regardless of the numberof threads in the process. The function shall be equivalent to <i>sigprocmask</i>(), without the restriction that the call be madein a single-threaded process. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p><p>In a single-threaded process, the <i>sigprocmask</i>() function shall examine or change (or both) the signal mask of the callingthread.</p><p>If the argument <i>set</i> is not a null pointer, it points to a set of signals to be used to change the currently blockedset.</p><p>The argument <i>how</i> indicates the way in which the set is changed, and the application shall ensure it consists of one ofthe following values:</p><dl compact><dt>SIG_BLOCK</dt><dd>The resulting set shall be the union of the current set and the signal set pointed to by <i>set</i>.</dd><dt>SIG_SETMASK</dt><dd>The resulting set shall be the signal set pointed to by <i>set</i>.</dd><dt>SIG_UNBLOCK</dt><dd>The resulting set shall be the intersection of the current set and the complement of the signal set pointed to by<i>set</i>.</dd></dl><p>If the argument <i>oset</i> is not a null pointer, the previous mask shall be stored in the location pointed to by <i>oset</i>.If <i>set</i> is a null pointer, the value of the argument <i>how</i> is not significant and the thread's signal mask shall beunchanged; thus the call can be used to enquire about currently blocked signals.</p><p>If there are any pending unblocked signals after the call to <i>sigprocmask</i>(), at least one of those signals shall bedelivered before the call to <i>sigprocmask</i>() returns.</p><p>It is not possible to block those signals which cannot be ignored. This shall be enforced by the system without causing an errorto be indicated.</p><p>If any of the SIGFPE, SIGILL, SIGSEGV, or SIGBUS signals are generated while they are blocked, the result is undefined, unlessthe signal was generated by the <a href="../functions/kill.html"><i>kill</i>()</a> function, the <a href="../functions/sigqueue.html"><i>sigqueue</i>()</a> function, or the <a href="../functions/raise.html"><i>raise</i>()</a>function.</p><p>If <i>sigprocmask</i>() fails, the thread's signal mask shall not be changed.</p><p>The use of the <i>sigprocmask</i>() function is unspecified in a multi-threaded process.</p></blockquote><h4><a name="tag_03_573_04"></a>RETURN VALUE</h4><blockquote><p><sup>[<a href="javascript:open_code('THR')">THR</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">Upon successful completion <i>pthread_sigmask</i>() shall return 0; otherwise, it shall return the corresponding error number. <imgsrc="../images/opt-end.gif" alt="[Option End]" border="0"></p><p>Upon successful completion, <i>sigprocmask</i>() shall return 0; otherwise, -1 shall be returned, <i>errno</i> shall be set toindicate the error, and the process' signal mask shall be unchanged.</p></blockquote><h4><a name="tag_03_573_05"></a>ERRORS</h4><blockquote><p><sup>[<a href="javascript:open_code('THR')">THR</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">The <i>pthread_sigmask</i>() <img src="../images/opt-end.gif" alt="[Option End]" border="0"> and <i>sigprocmask</i>() functionsshall fail if:</p><dl compact><dt>[EINVAL]</dt><dd>The value of the <i>how</i> argument is not equal to one of the defined values.</dd></dl><p><sup>[<a href="javascript:open_code('THR')">THR</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">The <i>pthread_sigmask</i>() function shall not return an error code of [EINTR]. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_03_573_06"></a>EXAMPLES</h4><blockquote><h5><a name="tag_03_573_06_01"></a>Signalling in a Multi-Threaded Process</h5><p>This example shows the use of <i>pthread_sigmask</i>() in order to deal with signals in a multi-threaded process. It provides afairly general framework that could be easily adapted/extended.</p><pre><tt>#include <stdio.h>#include <stdlib.h>#include <pthread.h>#include <signal.h>#include <string.h>#include <errno.h>...<br>static sigset_t signal_mask; /* signals to block */<br>int main (int argc, char *argv[]){ pthread_t sig_thr_id; /* signal handler thread ID */ int rc; /* return code */<br> sigemptyset (&signal_mask); sigaddset (&signal_mask, SIGINT); sigaddset (&signal_mask, SIGTERM); rc = pthread_sigmask (SIG_BLOCK, &signal_mask, NULL); if (rc != 0) { /* handle error */ ... } /* any newly created threads inherit the signal mask */<br> rc = pthread_create (&sig_thr_id, NULL, signal_thread, NULL); if (rc != 0) { /* handle error */ ... }<br> /* APPLICATION CODE */ ...}<br>void *signal_thread (void *arg){ int sig_caught; /* signal caught */ int rc; /* returned code */<br> rc = sigwait (&signal_mask, &sig_caught); if (rc != 0) { /* handle error */ } switch (sig_caught) { case SIGINT: /* process SIGINT */ ... break; case SIGTERM: /* process SIGTERM */ ... break; default: /* should normally not happen */ fprintf (stderr, "\nUnexpected signal %d\n", sig_caught); break; }}</tt></pre></blockquote><h4><a name="tag_03_573_07"></a>APPLICATION USAGE</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_573_08"></a>RATIONALE</h4><blockquote><p>When a thread's signal mask is changed in a signal-catching function that is installed by <a href="../functions/sigaction.html"><i>sigaction</i>()</a>, the restoration of the signal mask on return from the signal-catchingfunction overrides that change (see <a href="../functions/sigaction.html"><i>sigaction</i>()</a>). If the signal-catching functionwas installed with <a href="../functions/signal.html"><i>signal</i>()</a>, it is unspecified whether this occurs.</p><p>See <a href="kill.html"><i>kill</i>()</a> for a discussion of the requirement on delivery of signals.</p></blockquote><h4><a name="tag_03_573_09"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_573_10"></a>SEE ALSO</h4><blockquote><p><a href="sigaction.html"><i>sigaction</i>()</a>, <a href="sigaddset.html"><i>sigaddset</i>()</a>, <a href="sigdelset.html"><i>sigdelset</i>()</a>, <a href="sigemptyset.html"><i>sigemptyset</i>()</a>, <a href="sigfillset.html"><i>sigfillset</i>()</a>, <a href="sigismember.html"><i>sigismember</i>()</a>, <a href="sigpending.html"><i>sigpending</i>()</a>, <a href="sigqueue.html"><i>sigqueue</i>()</a>, <a href="sigsuspend.html"><i>sigsuspend</i>()</a>, the Base Definitions volume of IEEE Std 1003.1-2001, <a href="../basedefs/signal.h.html"><i><signal.h></i></a></p></blockquote><h4><a name="tag_03_573_11"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 3. Included for alignment with the POSIX.1-1988 standard.</p></blockquote><h4><a name="tag_03_573_12"></a>Issue 5</h4><blockquote><p>The DESCRIPTION is updated for alignment with the POSIX Threads Extension.</p><p>The <i>pthread_sigmask</i>() function is added for alignment with the POSIX Threads Extension.</p></blockquote><h4><a name="tag_03_573_13"></a>Issue 6</h4><blockquote><p>The <i>pthread_sigmask</i>() function is marked as part of the Threads option.</p><p>The SYNOPSIS for <i>sigprocmask</i>() is marked as a CX extension to note that the presence of this function in the <a href="../basedefs/signal.h.html"><i><signal.h></i></a> header is an extension to the ISO C standard.</p><p>The following changes are made for alignment with the ISO POSIX-1:1996 standard:</p><ul><li><p>The DESCRIPTION is updated to explicitly state the functions which may generate the signal.</p></li></ul><p>The DESCRIPTION is updated to avoid use of the term "must" for application requirements.</p><p>The <b>restrict</b> keyword is added to the <i>pthread_sigmask</i>() and <i>sigprocmask</i>() prototypes for alignment with theISO/IEC 9899:1999 standard.</p><p>IEEE Std 1003.1-2001/Cor 2-2004, item XSH/TC2/D6/105 is applied, updating "process' signal mask" to "thread'ssignal mask" in the DESCRIPTION and RATIONALE sections.</p><p>IEEE Std 1003.1-2001/Cor 2-2004, item XSH/TC2/D6/106 is applied, adding the example to the EXAMPLES section.</p></blockquote><div class="box"><em>End of informative text.</em></div><hr size="2" noshade><center><font size="2"><!--footer start-->UNIX ® is a registered Trademark of The Open Group.<br>POSIX ® is a registered Trademark of The IEEE.<br>[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>]</font></center><!--footer end--><hr size="2" noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -