当前位置:网站首页>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 .
边栏推荐
- Introduction and implementation of queue (detailed explanation)
- 魏建军骑宝马也追不上李书福
- Ansa secondary development - apps and ansa plug-in management
- 资本「断供」两年,我只能把公司卖了
- 在vs code上配置Hypermesh二次开发环境
- 微信公众号获取素材列表
- Reentrant and non reentrant
- Hdu1847 problem solving ideas
- LwIP development | realize TCP server through socket
- WSL+Valgrind+Clion
猜你喜欢

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

排序3-选择排序与归并排序(递归实现+非递归实现)

Kubeedge releases white paper on cloud native edge computing threat model and security protection technology

ABAQUS GUI interface solves the problem of Chinese garbled code (plug-in Chinese garbled code is also applicable)

使用js直传oss阿里云存储文件,解决大文件上传服务器限制

HyperMesh自动保存(增强版)插件使用说明

Using pyqt to design gui in ABAQUS

Sort 4-heap sort and massive TOPK problem

Several methods of HyperMesh running script files

一小时内学会Abaqus脚本编程秘籍
随机推荐
Redis series 4: sentinel (sentinel mode) with high availability
ANSYS二次开发 - MFC界面调用ADPL文件
Analysis of echo service model in the first six chapters of unp
解决电脑恶意广告弹窗的思路
信号屏蔽与处理
Introduction and implementation of queue (detailed explanation)
500million users, four years earlier than wechat... This app, which has been in operation for 15 years, will be permanently discontinued
微软100题-天天做-第11题
Sort 3-select sort and merge sort (recursive implementation + non recursive implementation)
PHP image synthesis technology
Wei Jianjun couldn't catch up with Li Shufu by riding a BMW
关于web对接针式打印机问题,Lodop使用
Ansa secondary development - build ansa secondary development environment on Visual Studio code
Record doc
Reentrant and non reentrant
Learn ABAQUS script programming script in an hour
Kubeedge releases white paper on cloud native edge computing threat model and security protection technology
"Weilai Cup" 2022 Niuke summer multi school training camp 3 h.hacker sam+ segment tree /dp/ divide and conquer (without the largest sub segment and of the inspection interval)
HDU1847解题思路
排序5-计数排序