当前位置:网站首页>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 .
边栏推荐
- Pop up layer prompt in the background
- Baidu editor ueeditor, when editing too much content, the toolbar is not visible, which is not convenient for editing or uploading problems
- 信号屏蔽与处理
- Some suggestions on optimizing HyperMesh script performance
- ANSA二次开发 - Apps和ANSA插件管理
- I can only sell the company after the capital has been "cut off" for two years
- Learn ABAQUS script programming script in an hour
- Redis系列4:高可用之Sentinel(哨兵模式)
- LeetCode每日一练 —— 剑指Offer 56 数组中数字出现的次数
- C language exception handling mechanism: jump function jump function setjmp/sigsetjmp and longjmp/siglongjmp
猜你喜欢

KubeEdge发布云原生边缘计算威胁模型及安全防护技术白皮书

IM即时通讯开发优化提升连接成功率、速度等

IT远程运维是什么意思?远程运维软件哪个好?

The video Number finds the golden key, and Tiktok imitates the latecomers

Configure HyperMesh secondary development environment on vs Code

WSL+Valgrind+Clion

8051 series MCU firmware upgrade IAP

魏建军骑宝马也追不上李书福

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

Thoughts on solving the pop-up of malicious computer advertisements
随机推荐
Several methods of HyperMesh running script files
nowcode-学会删除链表中重复元素两题(详解)
The local area network cannot access the Apache server
Design direction of daily development plan
微软100题-天天做-第11题
微信公众号获取素材列表
PHP mb_substr 中文乱码
关于MIT6.828_HW9_barriers xv6 homework9的一些问题
Kubeedge releases white paper on cloud native edge computing threat model and security protection technology
学会使用MySQL的Explain执行计划,SQL性能调优从此不再困难
CRC16 data verification supports modelbus and XMODEM verification modes (C language)
Redis系列4:高可用之Sentinel(哨兵模式)
Kubeedge releases white paper on cloud native edge computing threat model and security protection technology
Qt学习之信号和槽机制
Solve the width overflow of rich text pictures such as uniapp
加速投资的小红书,“病急乱投医”?
Use js direct OSS to store files in Alibaba cloud and solve the limitation of large file upload server
Curl returns blank or null without output. Solve the problem
PHP mb_ Substr Chinese garbled code
HyperMesh自动保存(增强版)插件使用说明