Trap和Interrupt有什么区别

Trap和Interrupt有什么区别

本文介绍了Trap和Interrupt有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

陷阱和中断有什么区别?

What is the difference between Trap and Interrupt?

如果不同系统的术语不同,那么它们在x86上意味着什么?

If the terminology is different for different systems, then what do they mean on x86?

推荐答案

一个 陷阱 是用户流程中的例外.它是由零除或无效的内存访问引起的.这也是调用内核例程(系统调用的常用方法),因为它们以更高的级别运行优先级高于用户代码.处理是同步的(因此,用户代码被挂起并随后继续).从某种意义上说,它们是活动的"-在大多数情况下,代码期望陷阱发生并依赖于此事实.

A trap is an exception in a user process. It's caused by division by zero or invalid memory access. It's also the usual way to invoke a kernel routine (a system call) because those run with a higher priority than user code. Handling is synchronous (so the user code is suspended and continues afterwards). In a sense they are "active" - most of the time, the code expects the trap to happen and relies on this fact.

中断 是由硬件(例如硬盘,图形卡,I/O端口等).这些是异步的(即它们不会在用户代码中可预测的位置发生)或被动"的,因为中断处理程序必须等待它们最终发生.

An interrupt is something generated by the hardware (devices like the hard disk, graphics card, I/O ports, etc). These are asynchronous (i.e. they don't happen at predictable places in the user code) or "passive" since the interrupt handler has to wait for them to happen eventually.

您还可以将陷阱视为一种CPU内部中断,因为陷阱处理程序的处理程序看起来像是中断处理程序(保存了寄存器和堆栈指针,存在上下文切换,在某些情况下可以恢复执行)离开).

You can also see a trap as a kind of CPU-internal interrupt since the handler for trap handler looks like an interrupt handler (registers and stack pointers are saved, there is a context switch, execution can resume in some cases where it left off).

这篇关于Trap和Interrupt有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 18:16