在Unix中如何处理信号? [英] How are signals handled in Unix?

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

问题描述

我的问题是在Unix中如何处理信号.是通过创建新线程来处理还是有其他东西?还有信号到来时程序的执行流程是什么?

My question is that how are signals handled in Unix. Are they handled by making new thread or there is something else? Also what is the flow of execution of programme when a signal comes?

执行流程的意思是,假设我在函数X的中间,并且调用了另一个函数Y.因此,编译器会暂停功能X的执行,然后转到功能Y.完成函数Y之后,编译器将再次从暂停的位置继续执行程序X.同样,我想知道当信号到来时程序如何执行.

What I mean by flow of execution is that, let's say I am in middle of a function X and call to another function Y comes. So the compiler goes pauses the execution of function X and goes to function Y. After finishing the function Y the compiler again continues the execution of programme X from where it was paused. Similarly I would like to know how programme executes when a signal comes.

我在程序中使用settimer来执行功能.但是,当我降低interval value时,该函数将再次被调用,并且先前的执行将被取消,尽管我不确定.该代码太乱且太长,因此我没有在这里发布它.

I am using settimer in my programme to execute a function. But when I lower the interval value the function is called again and previous execution is cancelled, though I am not sure about it. The code is too messy and long so I have not posted it here.

感谢您的关注..!

推荐答案

操作系统停止运行接收信号的线程,并运行信号处理程序.当它返回时,原始线程将从原来的位置重新启动.

The operating system stops running the thread receiving the signal and runs the signal handler. When it returns the original thread restarts where it was.

如果在另一个信号进入时信号处理程序已经在运行,则可以在sigaction调用中配置该操作.

If the signal handler is already running when another signal comes in, the action is configurable in the sigaction call.

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

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