"Sigprocmask system call"
Function Description: Sets the processing mode of the signal in the signal shielding set (blocking or not blocking).
Usage:
#include <signal.h>
int sigprocmask (int how, const sigset_t *set, sigset_t *oldset);
Parameters:
How: Used to specify the way the signal is modified, there may be a choice of three
Sig_block//Join signal to process mask.
Sig_unblock//Remove the signal from the process shield.
Sig_setmask//Sets the value of the set to the new process mask.
Set: As a pointer to the signal set, this refers to the new set of signals, if you want to read only the current mask value, you can set it to null.
Oldset: Also a pointer to the signal set, where the original signal set is stored.
Return Description:
When executed successfully, returns 0. The failed return -1,errno is set to Einval.
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
#include <>
static void Sig_quit (int signo)
{
printf ("Caught sigquit/n");
Signal (Sigquit, SIG_DFL);//Set the action of Sigquit to the default value
}
int main ()
{
sigset_t Newmask;
sigset_t Oldmask;
sigset_t Pendmask;
Signal (Sigquit, sig_quit);//Semaphore capture function, Snap to sigquit, jump to function pointer Sig_quit execute
Sigemptyset (&newmask);//Initialize semaphore set
Sigaddset (&newmask, sigquit);//Add Sigquit to the semaphore set
Sigprocmask (Sig_block, &newmask, &oldmask);//The Newmask in Sigquit is blocked off,and save the current signal screen word to Oldmask
Sleep (5);//Sleep for 5 seconds,here is the explanation: During 5s sleep, any sigquit signal will be blocked, if you receive any keyboard quit signal in 5s, then this information will be present in the kernel queue, waiting for the end of 5s, you may want to process this signal.
Sigpending (&pendmask);//Check the signal is pending,
if (Sigismember (&pendmask, sigquit))//sigquit is pending. The so-called unresolved means that Sigquit is blocked and has not been processed.
{
printf ("/nsigquit pending/n");
}
Sigprocmask (Sig_setmask, &oldmask, NULL);//Recover the masked signal sigquit
/** begins processing the signal and invokes the signal processing function.
printf ("Sigquit unblocked/n");
Sleep (5);//Sleep again for 5 seconds
return (0);
}
The above example is the Linux redhat,
Execution results are
$./a.out
^/ /** here uses "ctrl+/" to produce sigquit * /
Sigquit pending
Caught Sigquit handles the blocking signal sigquit before Sigprocmask returns, outputting it
Sigquit unblocked
^/quit (Coredump)//Because it has been set to the default value, so the sigquit signal is generated again, directly exit
"Sigpending system call"
#include <signal.h>
int sigpending (sigset_t *set);
The Sigpending function returns a set of signals in which each signal is blocked for the calling process and cannot be delivered, and therefore must be pending. The signal set is returned by the set parameter.
Linux signal Set