371 lines
10 KiB
HTML
371 lines
10 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<meta name="Copyright" content="Copyright (c) 2006 by IBM Corporation">
|
|
<title>sigprocmask()--Examine and Change Blocked Signals</title>
|
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
|
<!-- US Government Users Restricted Rights -->
|
|
<!-- Use, duplication or disclosure restricted by -->
|
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
|
<!-- Begin Header Records ========================================== -->
|
|
<!-- UNIX5 SCRIPT J converted by B2H R4.1 (346) (CMS) by V2KEA304 -->
|
|
<!-- at RCHVMW2 on 17 Feb 1999 at 11:05:09 -->
|
|
<!-- Edited by Kersten Feb 02 -->
|
|
<!-- This file has undergone error condition cleanup on 04/30/02 by JET -->
|
|
<!--End Header Records -->
|
|
<link rel="stylesheet" type="text/css" href="../rzahg/ic.css">
|
|
</head>
|
|
<body>
|
|
<a name="Top_Of_Page"></a>
|
|
<!-- Java sync-link -->
|
|
<script type="text/javascript" language="Javascript" src="../rzahg/synch.js">
|
|
</script>
|
|
|
|
<h2>sigprocmask()--Examine and Change Blocked Signals</h2>
|
|
|
|
<div class="box" style="width: 60%;">
|
|
<br>
|
|
Syntax<br>
|
|
<pre>
|
|
#include <signal.h>
|
|
|
|
int sigprocmask( int <em>how</em>, const sigset_t <em>*set</em>,
|
|
sigset_t <em>*oset</em> );
|
|
</pre>
|
|
|
|
<br>
|
|
Service Program Name: QPOSSRV1<br>
|
|
<!-- iddvc RMBR -->
|
|
<br>
|
|
Default Public Authority: *USE<br>
|
|
<!-- iddvc RMBR -->
|
|
<br>
|
|
Threadsafe: Yes<br>
|
|
<!-- iddvc RMBR -->
|
|
<br>
|
|
</div>
|
|
|
|
<p>The <strong>sigprocmask()</strong> function examines, or changes, or both
|
|
examines and changes the signal mask of the calling thread.</p>
|
|
|
|
<p>The signals SIGKILL or SIGStop cannot be blocked. Any attempt to use
|
|
<strong>sigprocmask()</strong> to block these signals is simply ignored, and no
|
|
error is returned.</p>
|
|
|
|
<p>SIGFPE, SIGILL, and SIGSEGV signals that are not artificially generated by
|
|
<strong>kill()</strong> or <strong>raise()</strong> (that is, were generated by
|
|
the system as a result of a hardware or software exception) are not
|
|
blocked.</p>
|
|
|
|
<p>If there are any pending unblocked signals after <strong>
|
|
sigprocmask()</strong> has changed the signal mask, at least one of those
|
|
signals is delivered to the thread before <strong>sigprocmask()</strong>
|
|
returns.</p>
|
|
|
|
<p>If <strong>sigprocmask()</strong> fails, the process's signal mask is not
|
|
changed.</p>
|
|
|
|
<br>
|
|
<!-- Please NOTE: DO NOT DELETE THIS SECTION if this API has no authorities and locks. -->
|
|
<!-- Instead, use the commented out coding below to indicate NONE. -->
|
|
<h3>Authorities and Locks</h3>
|
|
|
|
<!-- Use this if there are no authorities and locks. -->
|
|
<p>None.</p>
|
|
|
|
<br>
|
|
<h3>Parameters</h3>
|
|
|
|
<dl>
|
|
<dt><strong><em>how</em></strong></dt>
|
|
|
|
<dd>(Input) The way in which the signal set is changed.<br>
|
|
<br>
|
|
</dd>
|
|
|
|
<dt><strong><em>*set</em></strong></dt>
|
|
|
|
<dd>(Input) A pointer to a set of signals to be used to change the currently
|
|
blocked set. May be NULL.<br>
|
|
<br>
|
|
</dd>
|
|
|
|
<dt><strong><em>*oset</em></strong></dt>
|
|
|
|
<dd>(Output) A pointer to the space where the previous signal mask is stored.
|
|
May be NULL.</dd>
|
|
</dl>
|
|
|
|
<p>The possible values for <em>how</em>, which are defined in the
|
|
<<strong>sys/signal.h</strong>> header file, are as follows:</p>
|
|
|
|
<table cellpadding="5">
|
|
<!-- cols="15 85" -->
|
|
<tr>
|
|
<td align="left" valign="top"><em>SIG_BLOCK</em></td>
|
|
<td align="left" valign="top">Indicates that the set of signals given by <em>
|
|
set</em> should be blocked, in addition to the set currently being
|
|
blocked.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top"><em>SIG_UNBLOCK</em></td>
|
|
<td align="left" valign="top">Indicates that the set of signals given by <em>
|
|
set</em> should not be blocked. These signals are removed from the current set
|
|
of signals being blocked.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top"><em>SIG_SETMASK</em></td>
|
|
<td align="left" valign="top">Indicates that the set of signals given by <em>
|
|
set</em> should replace the old set of signals being blocked.</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<p>The <em>set</em> parameter points to a signal set giving the new signals
|
|
that should be blocked or unblocked (depending on the value of <em>how</em>),
|
|
or it points to the new signal mask if the value of <em>how</em> was
|
|
SIG_SETMASK. Signal sets are described in <a href="sigeset.htm">
|
|
sigemptyset()--Initialize and Empty Signal Set</a>. If <em>set</em> is a NULL
|
|
pointer, the set of blocked signals is not changed. If <em>set</em> is NULL,
|
|
the value of <em>how</em>is ignored.</p>
|
|
|
|
<p>The signal set manipulation functions (<strong>sigemptyset()</strong>,
|
|
<strong>sigfillset()</strong>, <strong>sigaddset()</strong>, and <strong>
|
|
sigdelset()</strong>) must be used to establish the new signal set pointed to
|
|
by <em>set</em>.</p>
|
|
|
|
<p><strong>sigprocmask()</strong> determines the current signal set and returns
|
|
this information in <em>*oset</em>. If <em>set</em> is NULL, <em>oset</em>
|
|
returns the current set of signals being blocked. When <em>set</em> is not
|
|
NULL, the set of signals pointed to by <em>oset</em> is the previous set.</p>
|
|
<br>
|
|
<h3>Return Value</h3>
|
|
|
|
<table cellpadding="5">
|
|
<!-- cols="5 95" -->
|
|
<tr>
|
|
<td align="left" valign="top"><em>0</em></td>
|
|
<td align="left" valign="top"><strong>sigprocmask()</strong> was
|
|
successful.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top"><em>-1</em></td>
|
|
<td align="left" valign="top"><strong>sigprocmask()</strong> was not
|
|
successful. The <em>errno</em> variable is set to indicate the error.</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<br>
|
|
<br>
|
|
<h3>Error Conditions</h3>
|
|
|
|
<p>If <strong>sigprocmask()</strong> is not successful, <em>errno</em> usually
|
|
indicates the following error. Under some conditions, <em>errno</em> could
|
|
indicate an error other than that listed here.</p>
|
|
|
|
<dl>
|
|
<dt><em>[EINVAL]</em></dt>
|
|
|
|
<dd>
|
|
<p>The value specified for the argument is not correct.</p>
|
|
|
|
<p>A function was passed incorrect argument values, or an operation was
|
|
attempted on an object and the operation specified is not supported for that
|
|
type of object.</p>
|
|
|
|
<p>An argument value is not valid, out of range, or NULL.</p>
|
|
|
|
<p>One of the following has occurred:</p>
|
|
|
|
<ul>
|
|
<li>The value of <em>how</em> is not equal to one of the defined values.</li>
|
|
|
|
<li>The signal set pointed to by <em>set</em> contains a signal that is not
|
|
within the valid range or a signal that is not supported.</li>
|
|
|
|
</ul>
|
|
</dd>
|
|
|
|
<dt><em>[ENOTSIGINIT]</em></dt>
|
|
|
|
<dd>
|
|
<p>Process not enabled for signals.</p>
|
|
|
|
<p>An attempt was made to call a signal function under one of the following
|
|
conditions:</p>
|
|
|
|
<ul>
|
|
<li>The signal function is being called for a process that is not enabled for
|
|
asynchronous signals.</li>
|
|
|
|
<li>The signal function is being called when the system signal controls have
|
|
not been initialized.</li>
|
|
</ul>
|
|
</dd>
|
|
</dl>
|
|
|
|
<br>
|
|
<h3>Usage Notes</h3>
|
|
|
|
<ol>
|
|
<li>When the <strong>sigprocmask</strong> function is used to change the signal
|
|
mask of the calling process, it enables the process for signals if the process
|
|
is not already enabled for signals. For details, see <a href="sigesig.htm">
|
|
Qp0sEnableSignals()--Enable Process for Signals</a>. If the system has not been
|
|
enabled for signals, <strong>sigprocmask()</strong> is not successful, and an
|
|
[ENOTSIGINIT] error is returned.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>Typically, <samp>sigprocmask(SIG_BLOCK, ...)</samp> is used to block
|
|
signals during a critical section of code. At the end of the critical section
|
|
of code, <samp>sigprocmask(SIG_SETMASK, ...)</samp> is used to restore the mask
|
|
to the previous value returned by <samp>sigprocmask(SIG_BLOCK,
|
|
...)</samp>.</li>
|
|
</ol>
|
|
|
|
<br>
|
|
<h3>Related Information</h3>
|
|
|
|
<ul>
|
|
<li>The <<strong>signal.h</strong>> file (see <a href="unix13.htm">Header
|
|
Files for UNIX-Type Functions</a>)<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="sigactn.htm">sigaction()</a>--Examine and Change Signal Action<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="sigdsig.htm">Qp0sDisableSignals()</a>--Disable Process for
|
|
Signals<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="sigesig.htm">Qp0sEnableSignals()</a>--Enable Process for
|
|
Signals<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="sigaset.htm">sigaddset()</a>--Add Signal to Signal Set<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="sigdset.htm">sigdelset()</a>--Delete Signal from Signal Set<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="sigeset.htm">sigemptyset()</a>--Initialize and Empty Signal
|
|
Set<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="sigfset.htm">sigfillset()</a>--Initialize and Fill Signal Set<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="sigismbr.htm">sigismember()</a>--Test for Signal in Signal Set<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="sigpend.htm">sigpending()</a>--Examine Pending Signals<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="sigsusp.htm">sigsuspend()</a>--Wait for Signal<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="sigtwait.htm">sigtimedwait()</a>--Synchronously Accept a Signal
|
|
for Interval of Time<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="sigwait.htm">sigwait()</a>--Synchronously Accept a Signal<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="sigwaiti.htm">sigwaitinfo()</a>--Synchronously Accept a Signal and
|
|
Signal Data</li>
|
|
</ul>
|
|
|
|
<br>
|
|
<h3>Example</h3>
|
|
|
|
<p>See <a href="../apiref/aboutapis.htm#codedisclaimer">Code disclaimer information</a>
|
|
for information pertaining to code examples.</p>
|
|
|
|
<p>The following example changes the signal mask:</p>
|
|
|
|
<pre>
|
|
#include <signal.h>
|
|
#include <unistd.h>
|
|
#include <stdio.h>
|
|
#include <time.h>
|
|
|
|
void catcher( int sig ) {
|
|
printf( "inside catcher() function\n" );
|
|
}
|
|
|
|
int main( int argc, char *argv[] ) {
|
|
|
|
time_t start, finish;
|
|
struct sigaction sact;
|
|
sigset_t new_set, old_set;
|
|
double diff;
|
|
|
|
sigemptyset( &sact.sa_mask );
|
|
sact.sa_flags = 0;
|
|
sact.sa_handler = catcher;
|
|
sigaction( SIGALRM, &sact, NULL );
|
|
|
|
sigemptyset( &new_set );
|
|
sigaddset( &new_set, SIGALRM );
|
|
sigprocmask( SIG_BLOCK, &new_set, &old_set);
|
|
|
|
time( &start );
|
|
printf( "SIGALRM signals blocked at %s\n", ctime(&start) );
|
|
|
|
alarm( 1 ); /* SIGALRM will be sent in 1 second */
|
|
|
|
do {
|
|
time( &finish );
|
|
diff = difftime( finish, start );
|
|
} while (diff < 10);
|
|
|
|
sigprocmask( SIG_SETMASK, &old_set, NULL );
|
|
printf( "SIGALRM signals unblocked at %s\n", ctime(&finish) );
|
|
|
|
return( 0 );
|
|
}
|
|
</pre>
|
|
|
|
<br>
|
|
<h3>Output:</h3>
|
|
|
|
<pre>
|
|
SIGALRM signals blocked at Sun Jan 22 16:53:40 1995
|
|
inside catcher() function
|
|
SIGALRM signals unblocked at Sun Jan 22 16:53:50 1995
|
|
</pre>
|
|
|
|
<br>
|
|
<hr>
|
|
API introduced: V3R6
|
|
|
|
<hr>
|
|
<center>
|
|
<table cellpadding="2" cellspacing="2">
|
|
<tr align="center">
|
|
<td valign="middle" align="center"><a href="#Top_Of_Page">Top</a> | <a href=
|
|
"unix.htm">UNIX-Type APIs</a> | <a href="aplist.htm">APIs by category</a></td>
|
|
</tr>
|
|
</table>
|
|
</center>
|
|
</body>
|
|
</html>
|
|
|