系统调用如何工作 [英] How does a system call work

查看:90
本文介绍了系统调用如何工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

系统调用如何工作?
系统调用期间会发生什么操作?
有各种各样的系统调用,例如open , read, write, socket等.我想知道它们通常如何工作?

How does system calls work ?
What are the operations happen during system call?
There are various system call like open , read, write, socket etc. I would like to know how do they work in general ?

推荐答案

简而言之,这是系统调用的工作方式:

In short, here's how a system call works:

  • 首先,用户应用程序为系统调用设置参数.
  • 所有参数设置完毕后,程序将执行系统调用"指令.
  • 此指令导致异常:一个事件,该事件导致处理器跳转到新地址并开始在该地址执行代码.

  • First, the user application program sets up the arguments for the system call.
  • After the arguments are all set up, the program executes the "system call" instruction.
  • This instruction causes an exception: an event that causes the processor to jump to a new address and start executing the code there.

新地址上的指令可保存用户程序的状态,找出所需的系统调用,在实现该系统调用的内核中调用该函数,恢复用户程序的状态,并将控制权返回给用户程序.

The instructions at the new address save your user program's state, figure out what system call you want, call the function in the kernel that implements that system call, restores your user program state, and returns control back to the user program.

用户应用程序调用open()系统调用的直观说明:

A visual explanation of a user application invoking the open() system call:

应注意,系统调用接口(它充当操作系统提供的系统调用的链接)在OS内核中调用预期的系统调用,并返回系统调用的状态和任何返回值. 调用方对系统调用的实现方式或执行过程的执行情况一无所知.
另一个示例:调用printf()库调用的C程序,该调用调用write()系统调用

It should be noted that the system call interface (it serves as the link to system calls made available by the operating system) invokes intended system call in OS kernel and returns status of the system call and any return values. The caller need know nothing about how the system call is implemented or what it does during execution.
Another example: A C program invoking printf() library call, which calls write() system call

有关更详细的说明,请从

For more detailed explanation read section 1.5.1 in CH-1 and Section 2.3 in CH-2 from Operating System Concepts.

这篇关于系统调用如何工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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