当前位置:网站首页>Signal shielding and processing
Signal shielding and processing
2022-07-28 16:42:00 【saddlesad】
Signal source and processing
There are many ways to generate signals :
- The user presses the shortcut key in the terminal ,shell Send the generated signal to the foreground process group . Such as Ctrl-C Trigger SIGINT The signal ,Ctrl-Z produce SIGTSTP The signal ,Ctrl+\ produce SIGQUIT The signal .
- Signal generated by hardware abnormality , If the divisor is 0 produce SIGFPE The signal , Invalid memory reference results SIGSEGV The signal .
- Program call kill The system call sends a signal to the specified process / Process group .
- Relevant software conditions occur , for example SIGURG,SIGPIPE,SIGALRM etc. .
The process can tell the kernel to take one of three actions to process the incoming signal :
Ignore this signal . The kernel will not notify the process of the generation of this signal , The application will not be able to obtain information about this signal .
Capture signal . The process needs to formulate a user function , It will be called when the signal arrives .
Perform system default actions . There is a kernel to decide whether to ignore the signal or terminate / Stop the process .
SIGKILL and SIGSTOP Cannot be ignored or captured .
Shielded signal word
We can use sigprocmask To set a masked signal word for the current process , Then the transmission of this signal will be blocked , in other words , If the kernel generates a blocked signal for the process , And the action on this signal is the system default action or capture this signal , Then the kernel keeps this signal pending , Until the process unblocks this signal , Or change the action of this signal to ignore .
The kernel only delivers the blocked signal to the process ( Not when this signal is generated ) Just decided how to deal with it . So the process is before the signal is delivered ( That is, it has been generated but is in a pending state due to blocking ) The action on this signal can still be changed .
If before the process unblocks a signal , This signal occurs many times , Then the process will only receive one delivery .( That is, the signal is not queued , However, the signal queuing function will be supported in the future ).
Signal shielding words are often set by signal sets / obtain . The signal set is sigset_t type ( It's usually unsigned int Of typedef), Its contents can be set by bit operation , Each value is 1 The bit of corresponds to a masked signal type .
#include <signal.h>
// Leave the signal set empty
int sigemptyset(sigset_t *set);
// Add all signals to the signal set
int sigfillset(sigset_t *set);
// Add signal signo To signal set
int sigaddset(sigset_t *set, int signo);
// Delete signal from signal set macro signo
int sigdelset(sigset_t *set, int signo);
this 4 Return values of functions : Successfully returns 0, Otherwise return to -1
// Judge whether there is a signal in the signal set signo
int sigismember(const sigset_t *set, int signo);
Return value : If you really return 1, Otherwise return to 0
To detect or obtain the signal shielding word , Use sigprocmask.
#include <signal.h>
int sigprocmask(int how, const sigset_t *restrict set, sigset_t *restrict oset);
Return value , If successful return 0, Otherwise return to -1
oset Will be set as the current signal mask word of the process ,set Is the new signal shielding word to be set .
how Indicates how to modify :
- SIG_BLOCK: Add set Signal in ( Union ).
- SIG_UNLOCK: Delete from the current signal shielding word set Signal in ( That is, the intersection of complements ).
- SIG_SETMASK: Directly set the current signal shielding word to set.
If oset or set by NULL, Then the old signal shielding word will not be obtained or the new signal shielding word will not be set .
If you call sigprocmask There are any pending 、 Signal that is currently no longer blocked , It's in sigprocmask Return to the former , The kernel delivers at least one of these signals to the process .
Check whether there are pending signals ( Produced but blocked ), Use sigpending.
#include <signal.h>
int sigpending(sigset_t *set);
Return value : If successful return 0, Otherwise return to -1
set Will be set as a signal set consisting of all currently pending signals .
边栏推荐
- Microsoft question 100 - do it every day - question 11
- “蔚来杯“2022牛客暑期多校训练营3 H.Hacker SAM+线段树/DP/分治(不带修查区间最大子段和)
- 学会使用MySQL的Explain执行计划,SQL性能调优从此不再困难
- Curl returns blank or null without output. Solve the problem
- Microsoft question 100 - do it every day - question 16
- WSL+Valgrind+Clion
- Ansa secondary development - build ansa secondary development environment on Visual Studio code
- 2021-04-02
- "Wei Lai Cup" 2022 Niuke summer multi school training camp 3 j.journey 0-1 shortest path
- Sdl2 concise tutorial (4): using SDL_ Image library importing pictures
猜你喜欢

LeetCode每日一练 —— 剑指Offer 56 数组中数字出现的次数
![[pointer internal skill cultivation] character pointer + pointer array + array pointer + pointer parameter (I)](/img/e8/2044cae63fe2145ce6294cb1fdfaa0.png)
[pointer internal skill cultivation] character pointer + pointer array + array pointer + pointer parameter (I)

一大早支付宝来短信说你中“奖”了?处理服务器挖矿病毒 - kthreaddi

疫情红利消失,「居家健身」泡沫消散

Debugging methods of USB products (fx3, ccg3pa)

Record doc

Learn ABAQUS script programming script in an hour

QT packaging

在abaqus中使用PyQt设计GUI

IM即时通讯开发优化提升连接成功率、速度等
随机推荐
laravel
队列的介绍与实现(详解)
Reentrant and non reentrant
"Wei Lai Cup" 2022 Niuke summer multi school training camp 3 a.ancestor lca+ violence count
栈的介绍与实现(详解)
The local area network cannot access the Apache server
ANSA二次开发 - 界面开发工具介绍
在vs code上配置Hypermesh二次开发环境
WSL+Valgrind+Clion
Ansa secondary development - build ansa/meta secondary development environment on pycharm
Ansa secondary development - apps and ansa plug-in management
Qt学习之信号和槽机制
What does it remote operation and maintenance mean? Which is the best remote operation and maintenance software?
PHP计算坐标距离
Early in the morning, pay Bora SMS to say that you won the "prize"? Dealing with server mining virus - kthreaddi
Configure HyperMesh secondary development environment on vs Code
PHP获取小程序码,小程序带参数跳转
Leetcode topic
一大早支付宝来短信说你中“奖”了?处理服务器挖矿病毒 - kthreaddi
PHP图片合成技术