Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* To ignore the signal. Sometimes we don't want a process *
- * to receive some certain signal(s). We can ignore those *
- * signal(s). For instance, SIGINT (ctrl-C), which is used *
- * to stop the process and the process can't continue. But *
- * SIGINT differs from SIGKILL and SIGSTOP as SIGINT can *
- * be caught or ignored. *
- * The following code, simply ignores SIGINT. */
- #include <signal.h>
- signal(SIGINT, SIG_IGN);
- /* After this code is reached any ctrl-C keyboard hit *
- * can't terminate the process. */
- /* ------------------------------------------------------- */
- /* To block signal. In case we want to defer or postpone *
- * delivery of some signals. We can simply do ... */
- /* variables are the set of signals i.e. oldmask & newmask */
- sigset_t oldmask, newmask; /* sigset_t is type of the set. */
- /* Make the set empty. */
- sigemptyset(&newmask);
- /* Add SIGINT to the set 'newmask'. */
- sigaddset(&newmask, SIGINT);
- /* Add SIGQUIT to the set 'newmask'. */
- sigaddset(&newmask, SIGQUIT);
- /* Add SIGTSTP to the set 'newmask'. */
- sigaddset(&newmask, SIGTSTP);
- /* Call sigprocmask(2) to defer those signals in 'newmask'. *
- * The 1st arg can be either SIG_BLOCK, SIG_UNBLOCK or *
- * SIG_SETMASK. In this example we want to block signals *
- * (actually defer or postpone delivery of the signal to *
- * the process). This example will block signals listed in *
- * 'newmask' and save the previous mask in 'oldmask'. */
- sigprocmask(SIG_BLOCK, &newmask, &oldmask);
- /* Do some stuff here. */
- /* All signals in the set, if any, are temporarily blocked. */
- /* We new restore 'oldmask' and allow all pending signals *
- * to deliver to the process. The 3rd arg is simply NULL. */
- sigprocmask(SIG_SETMASK, &oldmask, NULL);
- /* After this code is reached, the signals in the set are *
- * unblocked. All pending signals are delivered to the *
- * process. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement