信号在Linux中多线程处理 [英] Signal handling with multiple threads in Linux

查看:265
本文介绍了信号在Linux中多线程处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Linux上,当一个程序(即可能有多个线程)接收的信号,如SIGTERM或SIGHUP时会发生什么?

In Linux, what happens when a program (that possibly has multiple threads) receives a signal, like SIGTERM or SIGHUP?

哪个线程拦截信号?多线程可以得到相同的信号?有没有完全用于处理信号的特殊螺纹?如果没有,什么线程是处理信号里面发生什么呢?如何进行信号处理程序结束之后执行的简历?

Which thread intercepts the signal? Can multiple threads get the same signal? Is there a special thread dedicated entirely to handling signals? If not, what happens inside the thread that is to handle the signal? How does the execution resume after the signal handler routine finishes?

推荐答案

这是稍微细致入微,在此基础上正在使用版本的Linux内核。

This is slightly nuanced, based on which version of the Linux kernel you are using.

假设2.6 POSIX线程,如果你谈论的是OS发送SIGTERM或SIGHUP,将信号发送到过程,这是由接收和根线程来处理。使用POSIX线程,你也可以发送SIGTERM到各个线程为好,但我怀疑你是问什么时候该操作系统将信号发送到进程发生了什么。

Assuming 2.6 posix threads, and if you are talking about the OS sending SIGTERM or SIGHUP, the signal is sent to process, which is received by and handled by root thread. Using POSIX threads, you can also sent SIGTERM to individual threads as well, but I suspect you are asking about what happens when the OS sends the signal to the process.

在2.6,SIGTERM会导致子线程退出干净,其中2.4,子线程都处于不确定状态,离开了。

In 2.6, SIGTERM will cause child threads to exit "cleanly", where as 2.4, child threads were left in an indeterminate state.

这篇关于信号在Linux中多线程处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆