陷阱和中断有什么区别? [英] What is the difference between Trap and Interrupt?

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

问题描述

陷阱和中断有什么区别?

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 陷阱 是用户进程中的异常.它是由除以零或无效的内存访问引起的.这也是调用内核例程(系统调用)的常用方法,因为那些以更高优先于用户代码.处理是同步的(因此用户代码被挂起并在之后继续).从某种意义上说,它们是主动的"——大多数时候,代码期望陷阱发生并依赖于这个事实.

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).

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

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