Comprehensive experiment, SIGINT signal not set blocking, view pending keywords SIGINT signal Settings Blocking to view pending keywords SIGINT signal unblocked, view pending keyword (unblock via ctrl+\ sigquit) Demonstrate the entire process of signaling from generation to arrival A comprehensive experiment on blocking and unblocking of signals Set signal blocking and non-blocking, set ctl+q to unblock signal void handler (int sig) { if (sig = = SIGINT) printf ("Recv a sig=%d\n", SIG); else if (sig = = Sigquit) { sigset_t Uset; Sigemptyset (&uset); Sigaddset (&uset, SIGINT); Ctr + \ Used to contact SIGINT signal Unblocking Sigprocmask (Sig_unblock, &uset, NULL); } } void Printsigset (sigset_t *set) { int i; for (I=1; i<nsig; ++i) { if (Sigismember (set, i)) Putchar (' 1 '); Else Putchar (' 0 '); } printf ("\ n"); } 3 consecutive Press CTRL + C keyboard, although sent a plurality of SIGINT signals, but because the signal is not stable, only one reserved. Queuing is not supported int main (int argc, char *argv[]) { sigset_t PSet; The set of signals used to print sigset_t bset; Used to set the blocked signal set Sigemptyset (&bset); Sigaddset (&bset, SIGINT); if (signal (SIGINT, handler) = = Sig_err) Err_exit ("Signal error"); if (signal (sigquit, handler) = = Sig_err) Err_exit ("Signal error"); Read or change the signal screen word of a process here to block the CTRL + C signal The CTRL + C signal is set to block, even if the user presses the Ctl+c keyboard and does not arrive Sigprocmask (Sig_block, &bset, NULL); for (;;) { Get pending word Information Sigpending (&pset); Print signal pending sigset_t Word Printsigset (&pset); Sleep (1); } return 0; } |