惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
量子位
大猫的无限游戏
大猫的无限游戏
Hugging Face - Blog
Hugging Face - Blog
S
SegmentFault 最新的问题
Blog — PlanetScale
Blog — PlanetScale
月光博客
月光博客
Google DeepMind News
Google DeepMind News
小众软件
小众软件
WordPress大学
WordPress大学
宝玉的分享
宝玉的分享
MongoDB | Blog
MongoDB | Blog
B
Blog RSS Feed
博客园 - Franky
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
B
Blog
博客园 - 聂微东
The GitHub Blog
The GitHub Blog
Recent Announcements
Recent Announcements
Y
Y Combinator Blog
Microsoft Security Blog
Microsoft Security Blog
雷峰网
雷峰网
Jina AI
Jina AI
酷 壳 – CoolShell
酷 壳 – CoolShell

博客园 - 水色天空

用docfx生成c#项目API的简洁教程 wpf datagrid鼠标穿透 OxyPloot设置X轴时间DateTimeAxis WPF中MVVM模式下ComboBox绑定,无法更新selectedItem的解决方案 WPF设置DatePicker日期格式之卡Bug大法 WPF程序自动重启 InstallShield打包.net项目无法包含数据库、配置文件等 handycontrol中NumericUpDown无法显示自定义错误提示的解决办法 DataGrid代码生成列居中问题 Chapter 2 - Sockets and Patterns【选译,哈哈】 Part 9 High-Water Marks Chapter 2 - Sockets and Patterns【选译,哈哈】 Part 9 Missing Message Problem Solver Chapter 2 - Sockets and Patterns【选译,哈哈】 Part 9 Zero-Copy Chapter 2 - Sockets and Patterns【选译,哈哈】 Part 8 Node Coordination Chapter 2 - Sockets and Patterns【选译,哈哈】 Part 6 Multithreading with ZeroMQ Chapter 2 - Sockets and Patterns【选译,哈哈】 Part 7 Signaling Between Threads (PAIR Sockets) WPF绑定RadioButton的标准做法 解决.net reactor加密后的dll,在其它电脑无法运行的问题 函数返回值的一些规则 Chapter 2 - Sockets and Patterns【选译,哈哈】 Part 4 Handling Errors and ETERM
Chapter 2 - Sockets and Patterns【选译,哈哈】 Part 5 Han...
水色天空 · 2021-09-24 · via 博客园 - 水色天空

Handling Interrupt Signals

现实的应用程序需要在被Ctrl-C或SIGTERM等其他信号中断时干净地关闭。默认情况下,这些命令会杀死进程,这意味着消息不会被刷出,文件不会被干净地关闭,等等。

程序提供了s_catch_signals(),它捕获Ctrl-C (SIGINT)和SIGTERM。当这些信号到达时,s_catch_signals()处理程序设置全局变量s_interrupted。由于您的信号处理程序,您的应用程序不会自动死亡。相反,你有机会清理并优雅地退出。您现在必须显式地检查中断并正确地处理它。通过在主代码的开头调用s_catch_signals()(从interrupt.c中复制)来实现这一点。这就建立了信号处理。中断会对ZeroMQ调用产生如下影响:

如果代码在阻塞调用中阻塞(发送消息、接收消息或轮询),那么当信号到达时,调用将返回EINTR。

 像s_recv()这样的包装器在被中断时返回NULL。

因此,检查EINTR返回代码,NULL返回,和/或s_interrupted。

如果调用s_catch_signals()而不测试中断,则应用程序将不受Ctrl-C和SIGTERM的影响,这可能很有用,但通常不是。