sigprocmask

How to block signals in C?

醉酒当歌 提交于 2019-12-23 03:22:38
问题 I'm trying to create a program that blocks the signal SIGUSR1 and the it unblocks the signal. In the middle I want to see that the signal is blocked using sigpending . But it always says that the signal isn't blocked, and I can use the signal when it's supposed to be blocked. This is the code that I have. #include <stdlib.h> #include <stdio.h> #include <signal.h> static void signals(int signaln) { switch (signaln) { case SIGUSR1: printf("Signal SIGUSR1\n"); break; } return; } main() { sigset

sigprocmask during signal's execution

↘锁芯ラ 提交于 2019-12-11 01:09:36
问题 I'm currently researching using sigprocmask to block certain signals (in this case, SIGALRM and SIGCHLD ) when a critical segment of code is executing. Both of the signal handlers associated with these signals will access and modify a central data structure, so it is crucial that I prevent them from accessing it while the main process is working on it. At the moment, my plan would be to simply disable these signals at the start of the critical section of code, and then re-enable them at the

How to block signals in C?

混江龙づ霸主 提交于 2019-12-07 09:50:30
I'm trying to create a program that blocks the signal SIGUSR1 and the it unblocks the signal. In the middle I want to see that the signal is blocked using sigpending . But it always says that the signal isn't blocked, and I can use the signal when it's supposed to be blocked. This is the code that I have. #include <stdlib.h> #include <stdio.h> #include <signal.h> static void signals(int signaln) { switch (signaln) { case SIGUSR1: printf("Signal SIGUSR1\n"); break; } return; } main() { sigset_t set,set2; struct sigaction sigs; sigs.sa_handler = signals; sigemptyset(&sigs.sa_mask); sigs.sa_flags

Set and Oldset in sigprocmask()

◇◆丶佛笑我妖孽 提交于 2019-12-03 02:44:52
问题 I haven't completely understood, how to use sigprocmask() . Particularly, how the set and oldset and its syntax work and how to use them. int sigprocmask(int how, const sigset_t *set, sigset_t *oldset); Please explain with an example, to block, say SIGUSR1 for a few seconds and then unblock and handle it. ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ 回答1: The idea is that you provide a mask in set , effectively a list of signals. The how argument says what you should do with the mask in set . You can either

Set and Oldset in sigprocmask()

元气小坏坏 提交于 2019-12-02 14:42:34
I haven't completely understood, how to use sigprocmask() . Particularly, how the set and oldset and its syntax work and how to use them. int sigprocmask(int how, const sigset_t *set, sigset_t *oldset); Please explain with an example, to block, say SIGUSR1 for a few seconds and then unblock and handle it. ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ The idea is that you provide a mask in set , effectively a list of signals. The how argument says what you should do with the mask in set . You can either use SIG_BLOCK to block the signals in the set list, or SIG_UNBLOCK to unblock them. Neither of these changes