Chapter Contents

Previous

Next
sigsuspend

sigsuspend



Replace Signal Mask and Suspend Execution

Portability: POSIX.1 conforming


SYNOPSIS
DESCRIPTION
RETURN VALUE
EXAMPLE
RELATED FUNCTIONS
SEE ALSO


SYNOPSIS

#include <signal.h>

int sigsuspend(const sigset_t *set);


DESCRIPTION

sigsuspend replaces the signal mask for a program with the set of signals addressed by set and suspends program execution until an unblocked signal is received. If there is no handler defined for that signal, the default signal action (usually abnormal termination) is performed. Otherwise, the signal mask in effect when sigsuspend was called is restored before the handler is called.

The most common use of this function is to unblock all signals while program execution is suspended. For example, the following code suspends execution until any signal occurs and then restores the previous mask to block whatever signals were blocked before sigsuspend was called

sigemptyset(&mask);
sigsuspend(&mask);

Because sigsuspend restores the previous mask when a signal is discovered, you can use this function to handle a single occurrence of a signal, even if several signals are pending.


RETURN VALUE

sigsuspend never returns unless interrupted by a signal. If sigsuspend returns, it returns -1.


EXAMPLE

#define _SASC_POSIX_SOURCE 1

#include <signal.h>
#include <stdio.h>

volatile int shutdown = 0;
struct sigaction int_action;
sigset_t blocked_set, empty_set;

int_action.sa_handler = &int_handler;
sigemptyset(&int_action.sa_mask);
int_action.flags = 0;
sigaction(SIGINT, &int_action, NULL);
sigemptyset(&blocked_set);
sigaddset(&blocked_set, SIGINT);
sigprocmask(&blocked_set);
sigemptyset(&empty_set);
   /* Wait for and handle interrupts one at a time. It  */
   /*  is assumed that the SIGINT handler sets shutdown */
   /*  to nonzero to cause program termination.         */
while(!shutdown)
   sigsuspend(&empty_set);


RELATED FUNCTIONS

ecbsuspend , sleep


SEE ALSO


Chapter Contents

Previous

Next

Top of Page

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