在Linux和Windows下实现信号? [英] Implementation of Signals under Linux and Windows?

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

问题描述

我对编程中使用 signals 并不陌生.我主要在C/C ++和Python中工作. 但是我有兴趣了解如何在Linux(或Windows)中实际实现信号.

I am not new to the use of signals in programming. I mostly work in C/C++ and Python. But I am interested in knowing how signals are actually implemented in Linux (or Windows).

操作系统是否在信号描述符表中的每条CPU指令之后检查是否还有要处理的已注册信号?还是由流程经理/调度员对此负责?

Does the OS check after each CPU instruction in a signal descriptor table if there are any registered signals left to process? Or is the process manager/scheduler responsible for this?

由于信号是异步的,难道CPU指令在完成之前就中断了吗?

As signal are asynchronous, is it true that a CPU instruction interrupts before it complete?

推荐答案

操作系统绝对不会处理每条指令.决不.太慢了.

The OS definitely does not process each and every instruction. No way. Too slow.

当CPU遇到问题(例如被0除,访问受限资源或未由物理内存备份的内存位置)时,它会生成一种特殊的中断,称为异常(不要与此类混淆) C ++/Java/etc高级语言异常摘要).

When the CPU encounters a problem (like division by 0, access to a restricted resource or a memory location that's not backed up by physical memory), it generates a special kind of interrupt, called an exception (not to be confused with C++/Java/etc high level language exception abstract).

操作系统处理这些异常.如果需要,并且有可能,它可以将异常反映回其起源的流程中.所谓的结构化异常处理(SEH)在Windows中就是这种反映. C信号应使用相同的机制来实现.

The OS handles these exceptions. If it's so desired and if it's possible, it can reflect an exception back into the process from which it originated. The so-called Structured Exception Handling (SEH) in Windows is this kind of reflection. C signals should be implemented using the same mechanism.

这篇关于在Linux和Windows下实现信号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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