In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "what are the signal set operation functions in Linux", which is easy to understand and clear. I hope it can help you solve your doubts. Let me lead you to study and learn what are the signal set operation functions in Linux.
The signal is called signal delivery from generation to arrival. The intermediate state of the signal from generation to delivery is called the pending state of the signal. The reason for the pending state may be that the signal is blocked, that is, the corresponding bit of the signal mask word (or blocking signal set, mask) is set to 1. Both the blocking signal set and the pending signal set are maintained by the kernel, and the whole process is shown below:
Sometimes we need to block a signal, so we need to modify the blocking signal set. So, how do we modify the blocking signal set? One method provided by the system is that we first create a set that is the same as the blocking signal set, and then use it to modify the blocking signal set.
The system provides a series of signal set setting functions. These functions are as follows:
Sigset_t set; signal set data type, essentially typedef unsigned long sigset_t; int sigemptyset (sigset_t * set); clear a signal set 0 int sigfillset (sigset_t * set); set a signal set to 1 int sigaddset (sigset_t * set, int signum); add a signal to the signal set int sigdelset (sigset_t * set, int signum); clear a signal from the signal set. The return values of the above functions are: success: 0 Failed:-1 int sigismember (const sigset_t * set, int signum); determine whether a signal is in the signal set return value: in set: 1; not in: 0; error:-1
After using these functions to create a signal set, how do you change the blocking signal set? The system provides another function: sigprocmask function.
The sigprocmask function can be used to mask or unmask the signal. The essence of the function is to use the signal set we created to change the blocking signal set.
Function prototype:
Int sigprocmask (int how, const sigset_t set, sigset_t oldset)
Return value:
Success: 0; failure:-1, set errno
Parameter explanation:
Set: the parameter passed in is a bitmap. The position 1 in set indicates which signal is blocked by the current process.
Oldset: output parameters to save the old signal shielding set. This is a little similar to setitimer.
Value of parameter how:
Assume that the current signal mask word is mask
SIG_BLOCK: when how is set to this value, set represents the signal that needs to be masked. Equivalent to mask = mask | set
SIG_UNBLOCK: when how is set to this, set indicates the signal that needs to be unshielded. Equivalent to mask = mask & ~ set
SIG_SETMASK: when how is set to this, set represents a new mask set that replaces the original mask and. Equivalent to mask = set if calling sigprocmask unblocks several current signals, at least one of them is delivered before the sigprocmask returns.
How do we read the pending signal set? The system provides the sigpending function.
Function prototype:
Int sigpending (sigset_t * set)
Parameter description: set output parameters.
Return value:
Return value: success: 0; failure:-1, set errno
Ex.: print the pending state of all conventional signals to the screen.
# include # include # include void printPending (sigset_t * set) {int I = 0; for (I = 0; I < 32; iTunes +) {if (sigismember (set, I) = = 1) printf ("1"); else printf ("0");} printf ("\ n");} int main () {sigset_t set, oldset, pendset; sigemptyset (& set) Sigaddset (& set, SIGQUIT); / / ctrl +\ will generate SIGQUIT signals sigprocmask (SIG_BLOCK, & set, & oldset); while (1) {sigpending (& pendset); printPending (& pendset); / / write a function to print the pending signal set sleep (1) }} these are all the contents of the article "what are the signal set operation functions in Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.