Hands-On System Programming with Linux by Kaiwan N. Billimoria

Hands-On System Programming with Linux by Kaiwan N. Billimoria

Author:Kaiwan N. Billimoria
Language: eng
Format: epub
Tags: COM046070 - COMPUTERS / Operating Systems / Linux, COM046030 - COMPUTERS / Operating Systems / UNIX, COM051060 - COMPUTERS / Programming Languages / C
Publisher: Packt Publishing
Published: 2018-10-31T10:13:04+00:00


Querying the signal mask

So, we understand that you can set the process's signal mask at the time of sigaction(2) (via the sa_mask member), or via the sigprocmask(2) system call (as mentioned previously). But how exactly can you query the state of the process signal mask at any arbitrary point in time?

Well, again, via the sigprocmask(2) system call. But, logically, this API sets a mask, right? This is the trick: if the first parameter set is set to NULL, then the second parameter is effectively ignored, while in the third parameter oldset, the current signal mask value is populated, and thus we can query the signal mask without altering it.

The ch11/query_mask program demonstrates this, the code is built upon our previous example sig2.c. Hence, we do not need to show the entire source; we just show the relevant code, in main():

[...]

/* Init sigaction:

* setup 'my_handler' as the signal handler function,

* trap just the SIGINT and SIGQUIT signals.

*/

memset(&act, 0, sizeof(act));

act.sa_handler = my_handler;

/* This is interesting: we fill the signal mask, implying that

* _all_ signals are masked (blocked) while the signal handler

* runs! */

sigfillset(&act.sa_mask);



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.