当前位置:网站首页>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
边栏推荐
- IPv6过渡技术-6to4手工隧道配置实验--尚文网络奎哥
- File rename
- [pyg] understand the messagepassing process, GCN demo details
- Summary of determinant knowledge points in Chapter 1 of Linear Algebra (Jeff's self perception)
- Shardingsphere dynamic data source
- PHP generates PDF tcpdf
- redis高级应用【密码防护、数据持久化、主从同步、哨兵模式、事务】【暂未完成(半成品)】
- 编译文件时报错:错误: 编码GBK的不可映射字符
- 渤、黄海的潮汐特征
- Download and install node, NPM and yarn
猜你喜欢
![Learning notes of C programming [compiled by Mr. Tan Haoqiang] (Chapter III sequence programming) 04 C sentence](/img/60/bae0e8d92a53bcd2b2de3fb22b3b99.jpg)
Learning notes of C programming [compiled by Mr. Tan Haoqiang] (Chapter III sequence programming) 04 C sentence

Summary of determinant knowledge points in Chapter 1 of Linear Algebra (Jeff's self perception)

ffmpeg下载安装教程及介绍

MongoDB簡介

小程序获取用户头像和昵称

MongoDB复制集【主从复制】

900w+ data, from 17s to 300ms, how to operate

MySQL MAC download and installation tutorial

NPM: the 'NPM' item cannot be recognized as the name of a cmdlet, function, script file, or runnable program. Please check the spelling of the name. If the path is included, make sure the path is corr

机械臂速成小指南(八):运动学建模(标准DH法)
随机推荐
C programming learning notes [edited by Mr. Tan Haoqiang] (Chapter III sequence programming) 05 data input and output
Limit of one question per day
监听对象中值变化及访问
Advanced redis applications [password protection, data persistence, master-slave synchronization, sentinel mode, transactions] [not completed yet (semi-finished products)]
Pat class B common function Usage Summary
MongoDB简介
[pyg] understand the messagepassing process, GCN demo details
Lvgl usage experience
[mathematical logic] propositional logic (propositional and connective review | propositional formula | connective priority | truth table satisfiable contradiction tautology)
Solve high and send system Currenttimemillis Caton
递归使用和多维数组对象变一维数组对象
New programmers use the isXXX form to define Boolean types in the morning, and are discouraged in the afternoon?
解决高並發下System.currentTimeMillis卡頓
Unity3d RPG implementation (medium)
Limit of one question per day
File rename
可分离债券与可转债
动态规划:最长公共子串和最长公共子序列
On the adjacency matrix and adjacency table of graph storage
Mongodb replication set [master-slave replication]