博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Linux信号
阅读量:2359 次
发布时间:2019-05-10

本文共 1977 字,大约阅读时间需要 6 分钟。

From: http://cc.byexamples.com/20070520/tap-the-interrupt-signal/

 

When you hit control+c, you are actually send a SIGINT ( Interrupt signal ) to your program. By default, your program will be terminated after receiving SIGINT. But you can change the way of handling Interrupt signal.

Some of the application tends to ignore SIGINT. You can easily do that with sigaction.
Create a void function that intentionally do nothing. Create a sigaction structure variable, set the sa_handle point to the void fucntion. At last calling sigaction function, telling the system, while receiving SIGINT, call the void function.
Observed that the sigaction have to take 3 parameters, and the third param is to store the default sigaction structure for SIGINT. specify NULL for ignoring that.
What if I wanna tap the interrupt signal, do some operations and then allows the default SIGINT operation carry on? This can be very useful, for example, I want my program to log whatever in my memory to a file before the program terminate.
I save the default sigaction structure, and after finish running my handler operation, i reset my sigaction handler to default one and send myself SIGINT.

转载地址:http://phntb.baihongyu.com/

你可能感兴趣的文章
gdb调试
查看>>
C++智能指针、悬垂指针、哑指针、野指针
查看>>
JavaScript中的backgroundPosition的设置
查看>>
chrome模拟手机客户端模拟器使用方法
查看>>
让IE浏览器运行js时,不再提示“允许阻止内容”
查看>>
window.innerWidth和window.innerHeight
查看>>
在网页中嵌入Base64编码文件
查看>>
js的闭包概念
查看>>
js深拷贝和浅拷贝
查看>>
对JavaScript中call和apply的理解
查看>>
CSDN如何转载别人的文章
查看>>
Java之美[从菜鸟到高手演变]之Java学习方法
查看>>
Eclipse断点调试(debug)实用技巧——基础篇
查看>>
SpringMVC @SessionAttributes 使用详解以及源码分析
查看>>
小白虚拟机安装Linux(CentOS6.5 x86_64)
查看>>
MyBatis框架总结
查看>>
JVM学习总结
查看>>
C#位运算
查看>>
会议室预订源码
查看>>
素小暖讲Java
查看>>