Chapter Contents

Previous

Next
sigblock

sigblock



Inhibit Discovery of Asynchronous Signals

Portability: SAS/C extension, UNIX compatible


SYNOPSIS
DESCRIPTION
RETURN VALUE
CAUTION
PORTABILITY
EXAMPLE
RELATED FUNCTIONS
SEE ALSO


SYNOPSIS

#include <lcsignal.h>

int sigblock(int mask);


DESCRIPTION

sigblock delays discovery of one or more asynchronous signals. The mask argument is an integer that is interpreted as a bit string. You use this bit string to alter a mask of blocked signals. For example, the following call requests that the SIGALRM signal be blocked:

sigblock(1<<(SIGALRM - 1));

You can use this format to block any single asynchronous signal managed by SAS/C; simply change the name of the signal to be blocked.

By specifying a mask of 0, you also can use sigblock to determine what signals are currently blocked without making any changes.

The SAS/C library honors only bits corresponding to the asynchronous signals (SIGINT, SIGALRM, SIGIUCV, and SIGASY1 through SIGASY8); any other bits set in the mask are ignored. sigblock changes the status of only the bits specified in the argument. All other bits in the mask are unchanged; that is, if any of them were previously blocked, they remain blocked. Also, sigblock does not affect any signals managed by USS. For this reason, sigprocmask , which can be used for all signals, is preferable to sigblock .

If a signal occurs while it is blocked, the signal is kept pending until the signal is unblocked by a call to sigsetmask , sigpause , sigprocmask , sigsuspend , ecbpause , or ecbsuspend . When the signal is unblocked, it is discovered, and the appropriate handler is called. Refer to Blocking Signals for more information.

For compatibility with existing programs, a call to sigblock requesting that all signals be blocked (a signal mask of all ones) causes all blockable USS signals to be blocked as well. This blocking occurs within the library, so if you call sigblock(0xffffffff) and then use an exec function to transfer control to another program, that program receives control with no signals blocked.


RETURN VALUE

sigblock returns the previous mask of blocked signals. You can pass this value to the sigsetmask function to restore the previous set of blocked signals. Bits of the mask corresponding to synchronous signals are always 0.


CAUTION

You should not keep signals blocked for long periods of time because this may use large amounts of memory to queue pending signals. For lengthy programs, you should use sigblock to protect critical sections of the program and then reset the mask with sigsetmask to enable signals to occur freely in less critical areas.

The library sometimes uses sigblock to delay asynchronous signals during its own processing. If the library is in the middle of processing and something occurs that causes it to call longjmp to return to your program, the mask set by the library may still be in effect; that is, the mask may not be what you specified in your program. For example, suppose a library function runs out of stack space and raises SIGMEM, and the handler for SIGMEM returns to your program with a longjmp . You may need to issue sigsetmask at the completion of the jump to restore the signal mask needed by the program. The functions sigsetjmp and siglongjmp may be useful in these situations.

A signal generated by the program calling raise or siggen always occurs immediately, even if the signal is blocked.


PORTABILITY

sigblock is not portable, except to BSD-compatible UNIX systems.


EXAMPLE

The following code fragment illustrates the use of sigblock .

#include <lcsignal.h>

int old_mask;

   /* Hold up terminal attentions.    */
old_mask = sigblock(1<<(SIGINT-1));

   /* Perform critical code.          */
.
.
.
   /* Allow same interruptions again. */
sigsetmask(old_mask);


RELATED FUNCTIONS

sigpause , sigprocmask , sigsetmask


SEE ALSO


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.