当前位置:网站首页>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_DFLOne of . Only when thesa_handlerIs the address of the signal handler , or sa_handler The value isSIG_IGNandSIG_DFLoutside , That's rightsa_maskandsa_flagsFields are processed .sa_sigaction: If setSA_SIGINFOSign a , Will usesa_sigactionProcessing function , Otherwise usesa_handlerProcessing function .sa_mask: Define a set of signals , In the call bysa_handlerThe 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
边栏推荐
- Filter
- Summary of electromagnetic spectrum
- leetcode:动态规划模板
- npm : 无法将“npm”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。
- Advanced redis applications [password protection, data persistence, master-slave synchronization, sentinel mode, transactions] [not completed yet (semi-finished products)]
- Use three JS make a simple 3D scene
- 动态规划:最长回文子串和子序列
- The series of hyperbolic function in daily problem
- 释放数据力量的Ceph-尚文网络xUP楠哥
- navicat 导出数据库的表结构
猜你喜欢

Elsevier latex 提交文章 pdftex.def Error: File `thumbnails/cas-email.jpeg‘ not found: using draf

Summary of electromagnetic spectrum

Use three JS make a simple 3D scene
![[MySQL] the difference between left join, right join and join](/img/d4/8684cd59cd1bd77e70bd4d7c7074c3.jpg)
[MySQL] the difference between left join, right join and join

On the adjacency matrix and adjacency table of graph storage

简易版 微信小程序开发之页面跳转、数据绑定、获取用户信息、获取用户位置信息

900W+ 数据,从 17s 到 300ms,如何操作

用Three.js做一個簡單的3D場景
![C programming learning notes [edited by Mr. Tan Haoqiang] (Chapter III sequence programming) 03 operators and expressions](/img/4a/1df03d9f3315debb4c335260ed39f2.jpg)
C programming learning notes [edited by Mr. Tan Haoqiang] (Chapter III sequence programming) 03 operators and expressions
![[pyg] understand the messagepassing process, GCN demo details](/img/8b/8490aac98fd2753e661f74e284f43d.png)
[pyg] understand the messagepassing process, GCN demo details
随机推荐
[AI practice] Application xgboost Xgbregressor builds air quality prediction model (I)
Converts a timestamp to a time in the specified format
Compare float with 0
Captura下载安装及在Captura配置FFmpeg
Using jasmine to monitor constructors - spying on a constructor using Jasmine
[set theory] partial order relation (partial order relation definition | partial order set definition | greater than or equal to relation | less than or equal to relation | integer division relation |
node 开启服务器
float与0比较
navicat 导出数据库的表结构
Shardingsphere dynamic data source
Hi3536c v100r001c02spc040 cross compiler installation
npm : 无法将“npm”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。
使用InputFilter限制EditText时踩坑及解决方案
umi 路由拦截(简单粗暴)
Web会话管理安全问题
Introduction to mongodb
C # webrequest post mode, based on "basic auth" password authentication mode, uploads files and submits other data using multipart / form data mode
Tidal characteristics of the Bohai Sea and the Yellow Sea
Why does thread crash not cause JVM crash
900w+ data, from 17s to 300ms, how to operate