Linux Asynchronous-----Semaphore set

Source: Internet
Author: User

In practical applications an application needs to process multiple signals, and for convenience, the Linux system introduces the concept of a signal set. The signal set consists of a data type of multiple signals sigset_t. You can use the following system calls to set up the data contained in the signal set.

1, sigset_t in the/include/asm-generic/signal.h definition.

typedef struct {       unsignedlong sig[_nsig_words];  


2, the corresponding system call function:

<pre name= "code" class= "CPP" > #include <signal.h>    int sigemptyset (sigset_t *set);    int Sigfillset (sigset_t *set);    int Sigadd (sigset_t *set,int setnumber);    int Sigdelset (sigset_t *set,int setnumber); int Sigismember (const sigset_t set,int signumber)

Set represents a signal set pointer, Setnumber represents a signal.

The sigemptyset is used to set the set of signals that the set points to is empty, that is, does not contain any signals.

The sigfillset is used to set the set of signals that the set points to full, which contains all the signals.

The Sigaddset is used to add signals to the signal set.

The sigdelset is used to remove signals from the signal set.

The above function successfully returned 0, failed to return-1

The sigismember is used to detect if the signumber is in set, and if it belongs to return 1, it does not return 0.

3, sometimes do not want to receive the signal immediately stop the current execution, to deal with the signal, but also do not want to ignore the signal, but delay a period of time to call the signal processing function. This situation is achieved by blocking the signal.

"The difference between signal blocking and ignoring signals"

The concept of blocking and ignoring signals are different. The operating system does not speak the signal before it is unblocked by the process, the blocked signal does not affect the behavior of the process, and the signal is only temporarily blocked from passing. When a process ignores a signal, the signal is passed out, but the process discards the signal.

Sigprocmask set the processing mode of the signal in the signal shielding set (blocking or not blocking)

#include <signal.h>   int sigprocmask (ubt how,const sigset_t*set,sigset_t *oldset);  int sigsuspend (const sigset_t*sigmask);  
Parameters:

How: Used to specify the way the signal is modified, there may be a choice of three

Sig_block//adds the signal contained in the set point to the current signal mask. That is, the signal mask and set signal set are performed or manipulated.

sig_unblock//removes the signal contained in the signal set pointed to by set from the current signal mask. That is, the signal mask and set are performed and manipulated.

Sig_setmask//Sets the value of the set to the new process signal mask. That is, set assigns a signal mask to a value operation.

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. can be used to detect what signal is present in the signal mask.

Return Description:

When executed successfully, returns 0. The failed return -1,errno is set to Einval.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Linux Asynchronous-----Semaphore set

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.