Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/s/sigaction.html on line 1
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/s/sigaction.html on line 1
Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/s/sigaction.html on line 8
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/s/sigaction.html on line 8
Examine or specify the action associated with a signal
#include <signal.h>
int sigaction( int sig,
const struct sigaction * act,
struct sigaction * oact );
- sig
- The signal number (defined in <signal.h>).
For more information, see
“POSIX signals”
in the documentation for SignalAction().
- act
- NULL, or a pointer to a sigaction structure
that specifies how you want to modify the action for the given signal.
For more information about this structure, see below.
- oact
- NULL, or a pointer to a sigaction structure
that the function fills with information about the current action for
the signal.
libc
Use the -l c option to
qcc
to link against this library.
This library is usually included automatically.
You can use sigaction() to examine or specify (or both) the
action that's associated with a specific signal:
- If act isn't NULL, the specified signal is
modified.
- If oact isn't NULL, the previous action is
stored in the structure it points to.
The structure sigaction contains the following members:
- void (*sa_handler)();
- Address of a signal handler or action for nonqueued signals.
- void (*sa_sigaction)(int signo, siginfo_t* info, void* other);
- Address of a signal handler or action for queued signals.
- sigset_t sa_mask
- An additional set of signals to be masked (blocked) during execution of the signal-catching function.
- int sa_flags
- Special flags to affect behavior of the signal:
- SA_NOCLDSTOP is only used when the signal is
SIGCHLD.
It tells the system not to generate a SIGCHLD on the parent for children
who stop via SIGSTOP.
- SA_SIGINFO tells the OS to queue this signal.
The default is not to queue a signal delivered to a process.
If a signal isn't queued, setting the same signal multiple times on
a process or thread before it runs results in only the last signal's
being delivered.
If you set SA_SIGINFO, the signals are queued and
they're all delivered.
The sa_handler and sa_sigaction members of
act are implemented as a union and share common storage.
They differ only in their prototypes, with sa_handler being used
for
POSIX 1003.1a signals and sa_sigaction being used for POSIX 1003.1b queued realtime signals.
The values stored using either name can be one of:
- function
- The address of a signal catching function. See below for details.
- SIG_DFL
- This sets the signal to the default action:
- SIGCHLD, SIGIO, SIGURG and
SIGWINCH — ignore the signal (SIG_IGN).
- SIGSTOP — stop the process.
- SIGCONT — continue the program.
- All other signals — kill the process.
- SIG_IGN
- This ignores the signal.
Setting SIG_IGN for a signal that's pending discards all pending signals,
whether it's blocked or not.
New signals are discarded.
If you ignore SIGCHLD, your process's children don't
enter the zombie state and you're unable to
wait on their death using wait() or waitpid().
The function member of sa_handler or
sa_sigaction is always invoked with the following arguments:
void handler(int signo, siginfo_t *info, void *other)
If you have an old-style signal handler of the form:
void handler(int signo)
the extra arguments are still placed by the kernel, but the function
simply ignores them.
While in the handler, signo is masked, preventing
nested signals of the same type. In addition, any signals set in the
sa_mask member of act are also ORed into the
mask. When the handler returns through a normal return, the previous mask
is restored and any pending and now unmasked signals are acted
on. You return to the point in the program where it was
interrupted. If the thread was blocked in the kernel when the
interruption occurred, the kernel call returns with an
EINTR (see
ChannelCreate()
and
SyncMutexLock()
for exceptions to this).
The siginfo_t structure of the function in
sa_handler or sa_sigaction contains at least the
following members:
- int si_signo
- The signal number, which should match the signo argument
to the handler.
- int si_code
- A signal code, provided by the generator of the signal:
- SI_USER — the
kill()
function generated the signal.
- SI_QUEUE — the
sigqueue()
function generated the signal.
- SI_TIMER — a timer generated the signal.
- SI_ASYNCIO — asynchronous I/O generated the signal.
- SI_MESGQ — POSIX (not QNX) messages queues
generated the signal.
- union sigval si_value
- A value associated with the signal, provided by the
generator of the signal.
You can't ignore or catch SIGKILL or SIGSTOP.
Signal handlers and actions are defined for the process and affect all threads in the process.
For example, if one thread ignores a signal, then all threads ignore the signal.
You can target a signal at a thread, process, or process group (see
SignalKill()).
When targeted at a process, at most one thread receives the signal.
This thread must have the signal unblocked (see
SignalProcmask())
to be a candidate for receiving it.
All synchronously generated signals (e.g. SIGSEGV) are always
delivered to the thread that
caused them.
|
If you use
longjmp()
to return from a signal handler, the signal remains masked.
You can use
siglongjmp()
to restore the mask to the state saved by a previous call to
sigsetjmp(). |
- 0
- Success.
- -1
- An error occurred (errno is set).
- EAGAIN
- Insufficient system resources are available to set up the signal's action.
- EFAULT
- A fault occurred trying to access the buffers provided.
- EINVAL
- The signal signo isn't valid.
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
int main( void )
{
extern void handler();
struct sigaction act;
sigset_t set;
sigemptyset( &set );
sigaddset( &set, SIGUSR1 );
sigaddset( &set, SIGUSR2 );
/*
* Define a handler for SIGUSR1 such that when
* entered both SIGUSR1 and SIGUSR2 are masked.
*/
act.sa_flags = 0;
act.sa_mask = set;
act.sa_handler = &handler;
sigaction( SIGUSR1, &act, NULL );
kill( getpid(), SIGUSR1 );
/* Program will terminate with a SIGUSR2 */
return EXIT_SUCCESS;
}
void handler( signo )
{
static int first = 1;
if( first ) {
first = 0;
kill( getpid(), SIGUSR1 ); /* Prove signal masked */
kill( getpid(), SIGUSR2 ); /* Prove signal masked */
}
}
/*
* - SIGUSR1 is set from main(), handler() is called.
* - SIGUSR1 and SIGUSR2 are set from handler().
* - however, signals are masked until we return to main().
* - returning to main() unmasks SIGUSR1 and SIGUSR2.
* - pending SIGUSR1 now occurs, handler() is called.
* - pending SIGUSR2 now occurs. Since we don't have
* a handler for SIGUSR2, we are killed.
*/
POSIX 1003.1
Safety: | |
Cancellation point |
No |
Interrupt handler |
No |
Signal handler |
Yes |
Thread |
Yes |
errno,
kill(),
pthread_sigmask(),
raise(),
sigaddset(),
sigdelset(),
sigemptyset(),
sigfillset(),
sigismember(),
signal(),
SignalAction(),
SignalKill(),
sigpending(),
sigprocmask()
Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/s/sigaction.html on line 470
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/s/sigaction.html on line 470