当前位置:网站首页>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
边栏推荐
- Ffmpeg download and installation tutorial and introduction
- Hi3536c v100r001c02spc040 cross compiler installation
- Lvgl usage experience
- For instruction, uploading pictures and display effect optimization of simple wechat applet development
- Yolov5 project based on QT
- Captura下载安装及在Captura配置FFmpeg
- umi 路由拦截(简单粗暴)
- 900w+ data, from 17s to 300ms, how to operate
- 8.8.2-PointersOnC-20220214
- com. fasterxml. jackson. databind. Exc.invalidformatexception problem
猜你喜欢

Latest version of NPM: the "NPM" item cannot be recognized as the name of a cmdlet, function, script file, or runnable program. Please check

Web session management security issues

js中#号的作用

How to move towards IPv6: IPv6 Transition Technology - Shangwen network quigo
![Mongodb replication set [master-slave replication]](/img/2c/8030548455f45fa252062dd90e7b8b.png)
Mongodb replication set [master-slave replication]

Limit of one question per day

Introduction to mongodb

Bid farewell to artificial mental retardation: Mengzi open source project team received RMB 100 million financing to help NLP develop
![[MySQL] the difference between left join, right join and join](/img/d4/8684cd59cd1bd77e70bd4d7c7074c3.jpg)
[MySQL] the difference between left join, right join and join

Pat class B "1104 forever" DFS optimization idea
随机推荐
Elsevier latex submitted the article pdftex def Error: File `thumbnails/cas-email. jpeg‘ not found: using draf
MySQL MAC download and installation tutorial
IPv6过渡技术-6to4手工隧道配置实验--尚文网络奎哥
Dynamic programming: longest common substring and longest common subsequence
Unity3d RPG implementation (medium)
Use three JS make a simple 3D scene
The series of hyperbolic function in daily problem
TCP/IP模型中的重磅嘉宾TCP--尚文网络奎哥
Hutool动态添加定时任务
Null and undefined
Applet (continuous update)
如何迈向IPv6之IPv6过渡技术-尚文网络奎哥
@Accessors annotation function specifies that the prefix follows the hump naming
监听对象中值变化及访问
redis在服务器linux下的启动的相关命令(安装和配置)
Recursion: quick sort, merge sort and heap sort
Captura下载安装及在Captura配置FFmpeg
[mathematical logic] propositions and connectives (propositions | propositional symbolization | truth connectives | no | conjunction | disjunction | non truth connectives | implication | equivalence)
Introduction à mongodb
Summary of electromagnetic spectrum