当前位置:网站首页>Use of sigaction
Use of sigaction
2022-07-03 03:39:00 【___ Bozi mi pro】
sigaction Structure definition
struct sigaction
{
void (*sa_handler)(int);
void (*sa_sigaction)(int, siginfo_t*, void*);
sigset_t sa_mask;
int sa_flags;
};
sa_handler
: Address of the signal processor function , Or constantSIG_IGN
、SIG_DFL
One of . Only when thesa_handler
Is the address of the signal handler , or sa_handler The value isSIG_IGN
andSIG_DFL
outside , That's rightsa_mask
andsa_flags
Fields are processed .sa_sigaction
: If setSA_SIGINFO
Sign a , Will usesa_sigaction
Processing function , Otherwise usesa_handler
Processing function .sa_mask
: Define a set of signals , In the call bysa_handler
The defined processor program will block this set of signals , They are not allowed to interrupt the execution of this processor program .sa_flags
: Bitmask , Specify various options for controlling the signal processing process .SA_NODEFER
: When the signal is captured , This signal is not automatically added to the process mask when the processor program is executed .SA_ONSTACK
: When a processor function is called for this signal , Used bysigaltstack()
Optional stack installed .SA_RESETHAND
: When the signal is captured , The signal handling is reset to the default value before calling the processor function ( namelySIG_IGN
).SA_SIGINFO
: The signal processor program is called with additional parameters , It provides in-depth information about the signal
Use example 1 ( Use sa_handler)
void setupSignalHandlers(void)
{
struct sigaction act;
sigemptyset(&act.sa_mask);
act.sa_flags = SA_NODEFER | SA_ONSTACK | SA_RESETHAND;
act.sa_handler = sigtermHandler;
sigaction(SIGTERM, &act, NULL);
return;
}
static void sigtermHandler(int sig)
{
// TODO
}
Use example 2 ( Use sa_sigaction)
// Set up signal processing
void setupSignalHandlers(void)
{
struct sigaction act;
sigemptyset(&act.sa_mask);
act.sa_flags = SA_NODEFER | SA_ONSTACK | SA_RESETHAND | SA_SIGINFO;
act.sa_sigaction = sigsegvHandler;
sigaction(SIGSEGV, &act, NULL);
return;
}
static void sigsegvHandler(int sig, siginfo_t *info, void *secret)
{
// TODO
}
Processing of fatal signals such as segment errors
When a fatal signal such as a segment error is received , You can capture the signal first , Do something about it , For example, save call stack information , Then send the signal to the process , Make sure the program ends in a normal way , For example, set generation dump Documents, etc. .
struct sigaction act;
// TODO
sigemptyset (&act.sa_mask);
act.sa_flags = SA_NODEFER | SA_ONSTACK | SA_RESETHAND;
act.sa_handler = SIG_DFL;
sigaction (sig, &act, NULL);
kill(getpid(),sig);
Reference resources
- 《Linux/UNIX System programming manual 》
- https://github.com/antirez/redis/tree/2.2
边栏推荐
- The difference between static web pages and dynamic web pages & the difference between Web1.0 and Web2.0 & the difference between get and post
- MySQL MAC download and installation tutorial
- 解决高並發下System.currentTimeMillis卡頓
- Yolov5 project based on QT
- [embedded module] OLED display module
- 【学习笔记】seckill-秒杀项目--(11)项目总结
- Limit of one question per day
- 递归:快速排序,归并排序和堆排序
- 动态规划:最长回文子串和子序列
- Recursion: quick sort, merge sort and heap sort
猜你喜欢
Limit of one question per day
The series of hyperbolic function in daily problem
[embedded module] OLED display module
Application of derivative in daily question
C programming learning notes [edited by Mr. Tan Haoqiang] (Chapter III sequence programming) 05 data input and output
用Three.js做一个简单的3D场景
Web会话管理安全问题
Summary of determinant knowledge points in Chapter 1 of Linear Algebra (Jeff's self perception)
机械臂速成小指南(八):运动学建模(标准DH法)
用Three.js做一個簡單的3D場景
随机推荐
Ansible简介【暂未完成(半成品)】
[mathematical logic] propositional logic (propositional and connective review | propositional formula | connective priority | truth table satisfiable contradiction tautology)
Mongodb master profile
MongoDB主配置文件
Tidal characteristics of the Bohai Sea and the Yellow Sea
Numpy warning visibledeprecationwarning: creating an ndarray from ragged needed sequences
The series of hyperbolic function in daily problem
Introduction to mongodb
Small guide for rapid formation of manipulator (VIII): kinematic modeling (standard DH method)
[leetcode question brushing day 34] 540 Unique element in array, 384 Disrupt array, 202 Happy number, 149 Maximum number of points on a line
FileZilla client download and installation
For instruction, uploading pictures and display effect optimization of simple wechat applet development
softmax的近似之NCE详解
[MySQL] the difference between left join, right join and join
Node start server
用Three.js做一个简单的3D场景
[pyg] understand the messagepassing process, GCN demo details
C# WebRequest POST模式 ,基于“Basic Auth”口令认证模式,使用multipart/form-data方式上传文件及提交其他数据
umi 路由拦截(简单粗暴)
How to move towards IPv6: IPv6 Transition Technology - Shangwen network quigo