Linux signal and blocking

Source: Internet
Author: User
Article title: Linux signal and blocking. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

1. signal mask-blocked signal set

Each process has a signal set used to describe which signals are transmitted to be blocked. if a signal is in a blocked signal set of a process, the signal sent to the process will be blocked. The signal set currently blocked by the process is also called the signal mask, type: sigset_t. Each process has its own signal mask. when creating a child process, the child process inherits the signal mask of the parent process.

2. differences between signal blocking and ignoring

The concept of blocking is different from that of ignoring a signal: the operating system will not transmit the signal before the signal is blocked by the process. The blocked signal will not affect the process behavior, the signal is temporarily blocked. when a process ignores a signal, the signal is transmitted, but the process discards the signal.

3. signal set operations

The signal set can be operated by the following functions:

Int sigemptyset (sigset_t * set); // clear the signal set

Int sigfillset (sigset_t * set); // fill all signals in the set

Int sigaddset (sigset_t * set, int signum); // add the signal signum to the set.

Int sigdelset (sigset_t * set, int signum); // remove the signal signum from the set.

Int sigismember (const sigset_t * set, int signum); // determines whether signnum is included in the set. if 1 is returned, 0 is not returned.

During initialization, you can use sigemptyset () to clear the signal set, and then use sigaddset () to add signals to the signal set. Alternatively, you can use sigfillset () to add all signals to the signal set, and then use sigdelset () delete a signal from it.

4. sigprocmask () Introduction

You can use the sigprocmask () function to check or modify the signal mask of a process. The function information is as follows:

# Include

Int sigprocmask (int how, const sigset_t * restrict set,

Sigset_t * restrict old );

The parameter "how" is an integer that describes how to modify the signal mask:

SIG_BLOCK --- add signals from the set signal set to the current blocking signal set;

SIG_UNBLOCK --- remove the signal from the current blocked signal set to the signal set;

SIG_SETMASK --- specify the signal set to which the set points as the current blocked signal set.

In addition, if the set parameter is NULL, it does not need to be modified. if the old parameter is NULL, sigprocmask places the previously modified signal set in * old and returns the result.

5. sigaction () Review

Previously, the sigaction () function was used:

Include

Int sigaction (int signum, const struct sigaction * act,

Const struct sigaction * oldact );

This function is used to register a signal processing function. The parameter struct sigaction has the same name as the function. The details are as follows:

Struct sigaction {

Void (* sa_handler) (int); // pointer to the old signal processing function

Void (* sa_sigaction) (int, siginfo_t *, void *); // pointer to the new signal processing function

Sigset_t sa_mask; // set of signals to be blocked

Int sa_flags; // mask of the signal processing method

Void (* sa_restorer) (void); // reserved
}

[1] [2] Next page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.