248 lines
7.6 KiB
HTML
248 lines
7.6 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of PTHREAD_SIGMASK</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>PTHREAD_SIGMASK</H1>
|
|
Section: Linux Programmer's Manual (3)<BR>Updated: 2019-03-06<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
pthread_sigmask - examine and change mask of blocked signals
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
<B>#include <<A HREF="file:///usr/include/signal.h">signal.h</A>></B>
|
|
|
|
<B>int pthread_sigmask(int </B><I>how</I><B>, const sigset_t *</B><I>set</I><B>, sigset_t *</B><I>oldset</I><B>);</B>
|
|
</PRE>
|
|
|
|
<P>
|
|
|
|
Compile and link with <I>-pthread</I>.
|
|
<P>
|
|
|
|
|
|
Feature Test Macro Requirements for glibc (see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
|
|
|
|
|
|
<P>
|
|
|
|
|
|
<B>pthread_sigmask</B>():
|
|
|
|
<DL COMPACT><DT id="1"><DD>
|
|
_POSIX_C_SOURCE >= 199506L || _XOPEN_SOURCE >= 500
|
|
</DL>
|
|
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
The
|
|
<B>pthread_sigmask</B>()
|
|
|
|
function is just like
|
|
<B><A HREF="/cgi-bin/man/man2html?2+sigprocmask">sigprocmask</A></B>(2),
|
|
|
|
with the difference that its use in multithreaded programs
|
|
is explicitly specified by POSIX.1.
|
|
Other differences are noted in this page.
|
|
<P>
|
|
|
|
For a description of the arguments and operation of this function, see
|
|
<B><A HREF="/cgi-bin/man/man2html?2+sigprocmask">sigprocmask</A></B>(2).
|
|
|
|
<A NAME="lbAE"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
On success,
|
|
<B>pthread_sigmask</B>()
|
|
|
|
returns 0;
|
|
on error, it returns an error number.
|
|
<A NAME="lbAF"> </A>
|
|
<H2>ERRORS</H2>
|
|
|
|
See
|
|
<B><A HREF="/cgi-bin/man/man2html?2+sigprocmask">sigprocmask</A></B>(2).
|
|
|
|
<A NAME="lbAG"> </A>
|
|
<H2>ATTRIBUTES</H2>
|
|
|
|
For an explanation of the terms used in this section, see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
|
|
|
|
<TABLE BORDER>
|
|
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>pthread_sigmask</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>MT-Safe<BR></TD></TR>
|
|
</TABLE>
|
|
|
|
<A NAME="lbAH"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
POSIX.1-2001, POSIX.1-2008.
|
|
<A NAME="lbAI"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
A new thread inherits a copy of its creator's signal mask.
|
|
<P>
|
|
|
|
The glibc
|
|
<B>pthread_sigmask</B>()
|
|
|
|
function silently ignores attempts to block the two real-time signals that
|
|
are used internally by the NPTL threading implementation.
|
|
See
|
|
<B><A HREF="/cgi-bin/man/man2html?7+nptl">nptl</A></B>(7)
|
|
|
|
for details.
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>EXAMPLE</H2>
|
|
|
|
The program below blocks some signals in the main thread,
|
|
and then creates a dedicated thread to fetch those signals via
|
|
<B><A HREF="/cgi-bin/man/man2html?3+sigwait">sigwait</A></B>(3).
|
|
|
|
The following shell session demonstrates its use:
|
|
<P>
|
|
|
|
|
|
|
|
$<B> ./a.out &</B>
|
|
|
|
[1] 5423
|
|
$<B> kill -QUIT %1</B>
|
|
|
|
Signal handling thread got signal 3
|
|
$<B> kill -USR1 %1</B>
|
|
|
|
Signal handling thread got signal 10
|
|
$<B> kill -TERM %1</B>
|
|
|
|
[1]+ Terminated ./a.out
|
|
|
|
|
|
<A NAME="lbAK"> </A>
|
|
<H3>Program source</H3>
|
|
|
|
|
|
|
|
#include <<A HREF="file:///usr/include/pthread.h">pthread.h</A>>
|
|
#include <<A HREF="file:///usr/include/stdio.h">stdio.h</A>>
|
|
#include <<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>>
|
|
#include <<A HREF="file:///usr/include/unistd.h">unistd.h</A>>
|
|
#include <<A HREF="file:///usr/include/signal.h">signal.h</A>>
|
|
#include <<A HREF="file:///usr/include/errno.h">errno.h</A>>
|
|
<P>
|
|
/* Simple error handling functions */
|
|
<P>
|
|
#define handle_error_en(en, msg) \
|
|
<BR> do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0)
|
|
<P>
|
|
static void *
|
|
sig_thread(void *arg)
|
|
{
|
|
<BR> sigset_t *set = arg;
|
|
<BR> int s, sig;
|
|
<P>
|
|
<BR> for (;;) {
|
|
<BR> s = sigwait(set, &sig);
|
|
<BR> if (s != 0)
|
|
<BR> handle_error_en(s, "sigwait");
|
|
<BR> printf("Signal handling thread got signal %d\n", sig);
|
|
<BR> }
|
|
}
|
|
<P>
|
|
int
|
|
main(int argc, char *argv[])
|
|
{
|
|
<BR> pthread_t thread;
|
|
<BR> sigset_t set;
|
|
<BR> int s;
|
|
<P>
|
|
<BR> /* Block SIGQUIT and SIGUSR1; other threads created by main()
|
|
<BR> will inherit a copy of the signal mask. */
|
|
<P>
|
|
<BR> sigemptyset(&set);
|
|
<BR> sigaddset(&set, SIGQUIT);
|
|
<BR> sigaddset(&set, SIGUSR1);
|
|
<BR> s = pthread_sigmask(SIG_BLOCK, &set, NULL);
|
|
<BR> if (s != 0)
|
|
<BR> handle_error_en(s, "pthread_sigmask");
|
|
<P>
|
|
<BR> s = pthread_create(&thread, NULL, &sig_thread, (void *) &set);
|
|
<BR> if (s != 0)
|
|
<BR> handle_error_en(s, "pthread_create");
|
|
<P>
|
|
<BR> /* Main thread carries on to create other threads and/or do
|
|
<BR> other work */
|
|
<P>
|
|
<BR> pause(); /* Dummy pause so we can test program */
|
|
}
|
|
|
|
<A NAME="lbAL"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+sigaction">sigaction</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+sigpending">sigpending</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+sigprocmask">sigprocmask</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+pthread_create">pthread_create</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+pthread_kill">pthread_kill</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+sigsetops">sigsetops</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+pthreads">pthreads</A></B>(7),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+signal">signal</A></B>(7)
|
|
|
|
<A NAME="lbAM"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="2"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="3"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="4"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="5"><A HREF="#lbAE">RETURN VALUE</A><DD>
|
|
<DT id="6"><A HREF="#lbAF">ERRORS</A><DD>
|
|
<DT id="7"><A HREF="#lbAG">ATTRIBUTES</A><DD>
|
|
<DT id="8"><A HREF="#lbAH">CONFORMING TO</A><DD>
|
|
<DT id="9"><A HREF="#lbAI">NOTES</A><DD>
|
|
<DT id="10"><A HREF="#lbAJ">EXAMPLE</A><DD>
|
|
<DL>
|
|
<DT id="11"><A HREF="#lbAK">Program source</A><DD>
|
|
</DL>
|
|
<DT id="12"><A HREF="#lbAL">SEE ALSO</A><DD>
|
|
<DT id="13"><A HREF="#lbAM">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:53 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|