delorie.com/djgpp/doc/libc/libc_726.html | search |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
#include <signal.h> int sigprocmask (int how, const sigset_t *new_set, sigset_t *old_set) |
This function is used to examine and/or change the program's current
signal mask. The current signal mask determines which signals are
blocked from being delivered to the program. A signal is blocked if its
bit in the mask is set. (See section sigismember, See section sigaddset,
See section sigdelset, See section sigemptyset, See section sigfillset, for information
about functions to manipulate the signal masks.) When a blocked signal
happens, it is not delivered to the program until such time as that
signal is unblocked by another call to sigprocmask
. Thus
blocking a signal is an alternative to ignoring it (by setting its
handler to SIG_IGN
, see section signal), but has an advantage of not
missing the signal entirely.
The value of the argument how determines the operation: if it is
SIG_BLOCK
, the set pointed to by the argument new_set is
added to the current signal mask. If the value is
SIG_UNBLOCK
, the set pointed to by new_set is
removed from the current signal mask. If the value is
SIG_SETMASK
, the current mask is replaced by the set
pointed to by new_set.
If the argument old_set is not NULL
, the previous mask is
stored in the space pointed to by old_set. If the value of the
argument new_set is NULL
, the value of how is not
significant and the process signal mask is unchanged; thus, the call
with a zero new_set can be used to inquire about currently blocked
signals, without changing the current set.
If the new set defined by the call causes some pending signals to be
unblocked, they are all delivered (by calling raise
) before the
call to sigprocmask
returns.
The DJGPP implementation only records a single occurrence of any given signal, so when the signal is unblocked, its handler will be called at most once.
It is not possible to block CPU exceptions such as Page Fault, General
Protection Fault etc. (mapped to SIGSEGV
signal); for these,
sigprocmask
will behave as if the call succeeded, but when an
exception happens, the signal handler will be called anyway (the default
handler will abort the program).
Also note that there are no provisions to save and restore any
additional info about the signal beyond the fact that it happened. A
signal handler might need such info to handle the signal intelligently.
For example, a handler for SIGFPE
might need to examine the
status word of the FPU to see what exactly went wrong. But if the
signal was blocked and is delivered after a call to sigprocmask
has unblocked it, that information is lost. Therefore, if you need
access to such auxiliary information in the signal handler, don't block
that signal.
0 on success, -1 for illegal value of sig or illegal address in new_set or old_set.
ANSI/ISO C | No |
POSIX | 1003.2-1992; 1003.1-2001 |
#include <conio.h> #include <signal.h> static void sig_catcher (int signo) { cprintf ("\r\nGot signal %d\r\n", signo); } int main (void) { sigset_t sigmask, prevmask; signal (SIGINT, sig_catcher); sigemptyset (&sigmask); sigaddset (&sigmask, SIGINT); if (sigprocmask (SIG_SETMASK, &sigmask, &prevmask) == 0) cputs ("SIGINT blocked. Try to interrupt me now.\r\n"); while (!kbhit ()) ; cputs ("See? I wasn't interrupted.\r\n"); cputs ("But now I will unblock SIGINT, and then get the signal.\r\n"); sigprocmask (SIG_UNBLOCK, &sigmask, &prevmask); return 0; } |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
webmaster | delorie software privacy |
Copyright © 2004 | Updated Apr 2004 |