...
POSIX defines the sigaction(2)
function, which assigns handlers to signals like signal(2)
, but also allows one to explicitly set persistence. One can thus use sigaction(2)
and sidestep the race window on non-persistent OS's.
Code Block | ||
---|---|---|
| ||
/* Equivalent to signal( SIGUSR1, handler); but make signal persistent */ struct sigaction act; act.sa_handler = &handler; act.sa_flags = 0; if (sigfillset( &act.sa_mask) != 0) { /* handle error */ } if (sigaction(SIGUSR1, &act, NULL) != 0) { /* handle error */ } |
In fact, POSIX recommends sigaction(2)
and deprecates signal(2)
. Unfortunately, sigaction(2)
is not C99-compliant.
...
POSIX defines the sigaction(2)
function, which assigns handlers to signals like signal(2)
, but also allows one to explicitly set persistence. One can thus use sigaction(2)
and sidestep the race window on non-persistent OS's.
Code Block | ||
---|---|---|
| ||
/* Equivalent to signal( SIGUSR1, handler); */ but make signal non-persistent */ struct sigaction act; act.sa_handler = &handler; act.sa_flags = SA_RESETHAND; if (sigfillset( &act.sa_mask) != 0) { /* handle error */ } if (sigaction(SIGUSR1, &act, NULL) != 0) { /* handle error */ } |
In fact, POSIX recommends sigaction(2)
and deprecates signal(2)
. Unfortunately, sigaction(2)
is not C99-compliant.
...