是下一个语句之前要处理用kill发送到保障的父线程的信号? [英] Is a signal sent with kill to a parent thread guaranteed to be processed before the next statement?

查看:162
本文介绍了是下一个语句之前要处理用kill发送到保障的父线程的信号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,如果我在Linux上的子线程运行(使用pthreads的,如果该事项),我运行下面的命令

Okay, so if I'm running in a child thread on linux (using pthreads if that matters), and I run the following command

kill(getpid(), someSignal);

它在给定的信号发送到当前线程的父

it will send the given signal to the parent of the current thread.

我的问题:它是保证父母随后将立即得到CPU和处理信号(杀应用程序,如果它是一个SIGKILL或做任何其他,如果是一些其他的信号)的语句之前,以下杀()运行?或者是有可能 - 甚至可能 - ,无论命令如下杀()将信号由父线程处理之前运行

My question: Is it guaranteed that the parent will then immediately get the CPU and process the signal (killing the app if it's a SIGKILL or doing whatever else if it's some other signal) before the statement following kill() is run? Or is it possible - even probable - that whatever command follows kill() will run before the signal is processed by the parent thread?

推荐答案

信号得到异步传递,所以你不能指望线程处理他们立即处理它们;此外,它必须做一些工作来处理它。

Signals get delivered asynchronously, so you can't expect the thread handling them to handle them immediately; moreover, it will have to do some work to handle it.

和如果一个sigprocmask()执行呼叫已经掩盖了所有线程的信号,该信号将仅在后它是未掩蔽作用

And if a sigprocmask() call had masked the signal in all threads, the signal will only be acted upon after it is unmasked.

信号不会去任何特定的线程,除非你已经使用sigprocmask从你不想让他们线程掩盖他们。大多数的多线程程序做到这一点,具有交付给任意线程处理电平信号通常不是你想要的。

Signals don't go to any particular thread, unless you have used sigprocmask to mask them from the threads you don't want to get them. Most multithreaded programs do this, as having process-level signals delivered to arbitrary threads is usually not what you want.

这篇关于是下一个语句之前要处理用kill发送到保障的父线程的信号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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