{"id":5031,"date":"2022-12-20T18:37:04","date_gmt":"2022-12-20T21:37:04","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/pthread_sigmask-man3p\/"},"modified":"2022-12-20T18:37:04","modified_gmt":"2022-12-20T21:37:04","slug":"pthread_sigmask-man3p","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/pthread_sigmask-man3p\/","title":{"rendered":"PTHREAD_SIGMASK (man3p)"},"content":{"rendered":"<h1 align=\"center\">PTHREAD_SIGMASK<\/h1>\n<p> <a href=\"#PROLOG\">PROLOG<\/a><br \/> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#RETURN VALUE\">RETURN VALUE<\/a><br \/> <a href=\"#ERRORS\">ERRORS<\/a><br \/> <a href=\"#EXAMPLES\">EXAMPLES<\/a><br \/> <a href=\"#APPLICATION USAGE\">APPLICATION USAGE<\/a><br \/> <a href=\"#RATIONALE\">RATIONALE<\/a><br \/> <a href=\"#FUTURE DIRECTIONS\">FUTURE DIRECTIONS<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#COPYRIGHT\">COPYRIGHT<\/a> <\/p>\n<hr>\n<h2>PROLOG <a name=\"PROLOG\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This manual page is part of the POSIX Programmer\u2019s Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.<\/p>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">pthread_sigmask, sigprocmask \u2014 examine and change blocked signals<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">#include <signal.h><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">int pthread_sigmask(int <i>how<\/i>, const sigset_t *restrict <i>set<\/i>, <br \/> sigset_t *restrict <i>oset<\/i>); <br \/> int sigprocmask(int <i>how<\/i>, const sigset_t *restrict <i>set<\/i>, <br \/> sigset_t *restrict <i>oset<\/i>);<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>pthread_sigmask<\/i>() function shall examine or change (or both) the calling thread\u2019s signal mask, regardless of the number of threads in the process. The function shall be equivalent to <i>sigprocmask<\/i>(), without the restriction that the call be made in a single-threaded process.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">In a single-threaded process, the <i>sigprocmask<\/i>() function shall examine or change (or both) the signal mask of the calling thread.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">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 blocked set.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The argument <i>how<\/i> indicates the way in which the set is changed, and the application shall ensure it consists of one of the following values:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"17%\">\n<p>SIG_BLOCK<\/p>\n<\/td>\n<td width=\"1%\"><\/td>\n<td width=\"71%\">\n<p>The resulting set shall be the union of the current set and the signal set pointed to by <i>set<\/i>.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"17%\">\n<p>SIG_SETMASK<\/p>\n<\/td>\n<td width=\"1%\"><\/td>\n<td width=\"71%\">\n<p>The resulting set shall be the signal set pointed to by <i>set<\/i>.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"17%\">\n<p>SIG_UNBLOCK<\/p>\n<\/td>\n<td width=\"1%\"><\/td>\n<td width=\"71%\">\n<p>The resulting set shall be the intersection of the current set and the complement of the signal set pointed to by <i>set<\/i>.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%; margin-top: 1em\">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\u2019s signal mask shall be unchanged; thus the call can be used to enquire about currently blocked signals.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If there are any pending unblocked signals after the call to <i>sigprocmask<\/i>(), at least one of those signals shall be delivered before the call to <i>sigprocmask<\/i>() returns.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">It is not possible to block those signals which cannot be ignored. This shall be enforced by the system without causing an error to be indicated.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If any of the SIGFPE, SIGILL, SIGSEGV, or SIGBUS signals are generated while they are blocked, the result is undefined, unless the signal was generated by the action of another process, or by one of the functions <i>kill<\/i>(), <i>pthread_kill<\/i>(), <i>raise<\/i>(), or <i>sigqueue<\/i>().<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If <i>sigprocmask<\/i>() fails, the thread\u2019s signal mask shall not be changed.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The use of the <i>sigprocmask<\/i>() function is unspecified in a multi-threaded process.<\/p>\n<h2>RETURN VALUE <a name=\"RETURN VALUE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Upon successful completion <i>pthread_sigmask<\/i>() shall return 0; otherwise, it shall return the corresponding error number.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Upon successful completion, <i>sigprocmask<\/i>() shall return 0; otherwise, \u22121 shall be returned, <i>errno<\/i> shall be set to indicate the error, and the signal mask of the process shall be unchanged.<\/p>\n<h2>ERRORS <a name=\"ERRORS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>pthread_sigmask<\/i>() and <i>sigprocmask<\/i>() functions shall fail if:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p style=\"margin-top: 1em\"><b>EINVAL<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p style=\"margin-top: 1em\">The value of the <i>how<\/i> argument is not equal to one of the defined values.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>pthread_sigmask<\/i>() function shall not return an error code of <b>[EINTR]<\/b>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><i>The following sections are informative.<\/i><\/p>\n<h2>EXAMPLES <a name=\"EXAMPLES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><i><b>Signaling in a Multi-Threaded Process<\/b><\/i> <br \/> This example shows the use of <i>pthread_sigmask<\/i>() in order to deal with signals in a multi-threaded process. It provides a fairly general framework that could be easily adapted\/extended.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">#include <stdio.h> <br \/> #include <stdlib.h> <br \/> #include <pthread.h> #include <signal.h> <br \/> #include <string.h> <br \/> #include <errno.h> <br \/> &#8230;<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">static sigset_t signal_mask; \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var signals to block *\/<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">int main (int argc, char *argv[]) <br \/> { <br \/> pthread_t sig_thr_id; \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var signal handler thread ID bodies\/ usr\/ <br \/> int rc; \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var return code *\/<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">sigemptyset (&#038;signal_mask); <br \/> sigaddset (&#038;signal_mask, SIGINT); <br \/> sigaddset (&#038;signal_mask, SIGTERM); <br \/> rc = pthread_sigmask (SIG_BLOCK, &#038;signal_mask, NULL); <br \/> if (rc != 0) { <br \/> \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var handle error bodies\/ usr\/ <br \/> &#8230; <br \/> } <br \/> \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var any newly created threads inherit the signal mask *\/<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">rc = pthread_create (&#038;sig_thr_id, NULL, signal_thread, NULL); <br \/> if (rc != 0) { <br \/> \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var handle error bodies\/ usr\/ <br \/> &#8230; <br \/> }<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">\/* APPLICATION CODE bodies\/ usr\/ <br \/> &#8230; <br \/> }<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">void *signal_thread (void *arg) <br \/> { <br \/> int sig_caught; \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var signal caught bodies\/ usr\/ <br \/> int rc; \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var returned code *\/<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">rc = sigwait (&#038;signal_mask, &#038;sig_caught); <br \/> if (rc != 0) { <br \/> \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var handle error bodies\/ usr\/ <br \/> } <br \/> switch (sig_caught) <br \/> { <br \/> case SIGINT: \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var process SIGINT bodies\/ usr\/ <br \/> &#8230; <br \/> break; <br \/> case SIGTERM: \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var process SIGTERM bodies\/ usr\/ <br \/> &#8230; <br \/> break; <br \/> default: \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var should normally not happen bodies\/ usr\/ <br \/> fprintf (stderr, &#8220;nUnexpected signal %dn&#8221;, sig_caught); <br \/> break; <br \/> } <br \/> }<\/p>\n<h2>APPLICATION USAGE <a name=\"APPLICATION USAGE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">None.<\/p>\n<h2>RATIONALE <a name=\"RATIONALE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">When a thread\u2019s signal mask is changed in a signal-catching function that is installed by <i>sigaction<\/i>(), the restoration of the signal mask on return from the signal-catching function overrides that change (see <i>sigaction<\/i>()). If the signal-catching function was installed with <i>signal<\/i>(), it is unspecified whether this occurs.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">See <i>kill<\/i>() for a discussion of the requirement on delivery of signals.<\/p>\n<h2>FUTURE DIRECTIONS <a name=\"FUTURE DIRECTIONS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">None.<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><i>exec<\/i>, <i>kill<\/i>(), <i>sigaction<\/i>(), <i>sigaddset<\/i>(), <i>sigdelset<\/i>(), <i>sigemptyset<\/i>(), <i>sigfillset<\/i>(), <i>sigismember<\/i>(), <i>sigpending<\/i>(), <i>sigqueue<\/i>(), <i>sigsuspend<\/i>()<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The Base Definitions volume of POSIX.1-2017, <b><signal.h><\/b><\/p>\n<h2>COPYRIGHT <a name=\"COPYRIGHT\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology &#8212; Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http:\/\/www.opengroup.org\/unix\/online.html .<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https:\/\/www.kernel.org\/doc\/man-pages\/reporting_bugs.html .<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  pthread_sigmask, sigprocmask \u2014 examine and change blocked signals <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3779,1],"tags":[1594,1925],"class_list":["post-5031","post","type-post","status-publish","format-standard","hentry","category-3pm-perl-llamadas-de-bibliotecas","category-sin-categoria","tag-man3p","tag-pthread_sigmask"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/5031","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=5031"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/5031\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=5031"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=5031"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=5031"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}