当前位置:网站首页>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 .
边栏推荐
- MySQL view event status statements and modification methods
- Some suggestions on optimizing HyperMesh script performance
- Qt学习之信号和槽机制
- Analysis of echo service model in the first six chapters of unp
- 排序4-堆排序与海量TopK问题
- Optimization of network request success rate in IM instant messaging software development
- Reset grafana login password to default password
- LeetCode每日一练 —— 160. 相交链表
- Each account corresponds to all passwords, and then each password corresponds to all accounts. How to write the brute force cracking code
- 视频号找到金钥匙,抖音模仿后来人
猜你喜欢

排序2-冒泡排序与快速排序(递归加非递归讲解)

Ansa secondary development - two methods of drawing the middle surface

在abaqus中使用PyQt设计GUI

USB产品(FX3、CCG3PA)的调试方法

WSL+Valgrind+Clion

nowcode-学会删除链表中重复元素两题(详解)

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

IM即时通讯软件开发网络请求成功率的优化

SCI scientific paper writing Growth Camp (full version)

Some suggestions on optimizing HyperMesh script performance
随机推荐
LwIP development | realize TCP server through socket
IM即时通讯开发优化提升连接成功率、速度等
排序3-选择排序与归并排序(递归实现+非递归实现)
HyperMesh运行脚本文件的几种方法
Stm32cube infrared remote control: input capture
Ansa secondary development - two methods of drawing the middle surface
Sort 2 bubble sort and quick sort (recursive and non recursive explanation)
CRC16数据校验支持ModelBus和XMODEM校验模式(C语言)
排序4-堆排序与海量TopK问题
栈的介绍与实现(详解)
Configure HyperMesh secondary development environment on vs Code
PHP mb_substr 中文乱码
PHP 图片上传
排序2-冒泡排序与快速排序(递归加非递归讲解)
Geodetic coordinate system to Martian coordinate system
"Wei Lai Cup" 2022 Niuke summer multi school training camp 3 a.ancestor lca+ violence count
El input limit can only input the specified number
What does it remote operation and maintenance mean? Which is the best remote operation and maintenance software?
百度编辑器ueditor,编辑内容过多时,工具栏不可见,不方便编辑或上传问题
在vs code上配置Hypermesh二次开发环境