c - 用户空间进程抢占内核线程?

标签 c linux

目前我正在阅读“了解 Linux 内核,第 3 版”,在第 22 页我可以阅读:

In the simplest case, the CPU executes a kernel control path sequentially from the first instruction to the last. When one of the following events occurs, however, the CPU interleaves the kernel control paths:

  • A process executing in User Mode invokes a system call, and the corresponding kernel control path verifies that the request cannot be satisfied immediately; it then invokes the scheduler to select a new process to run. As a result, a process switch occurs. The first kernel control path is left unfinished, and the CPU resumes the execution of some other kernel control path. In this case, the two control paths are executed on behalf of two different processes.

内核控制路径可以从执行系统调用的用户空间进程中断吗? 我认为优先级差不多:

  • 打断
  • 内核线程
  • 用户空间进程

我已经检查了勘误表,但找不到任何关于此的信息。

最佳答案

关于优先级列表,你是对的,但(我认为)这本书想说的是:

  • 当(用户)进程进行系统调用时,内核开始代表它执行。
  • 如果系统调用可以完成(内核控制路径没有遇到障碍),那么它通常会直接返回调用进程 - 想想 getpid() 函数调用。<
  • 另一方面,如果系统调用无法完成(例如,因为磁盘系统必须在其数据返回给调用进程之前将一个 block 读入内核缓冲池),那么调度程序用于选择要运行的新进程 - 抢占(代表用户进程运行的内核控制线程)。
  • 在适当的时候,原始系统调用将能够继续,并且原始(代表运行的内核控制线程)用户进程将能够继续并最终完成,将控制权返回给用户空间在用户空间而不是内核中运行的进程。

所以“不”:“内核路径不会被执行系统调用的用户空间进程中断”。

内核路径在代表用户空间进程执行系统调用时可能会被中断,因为:发生中断,或者内核路径必须等待资源可用,或者......

关于c - 用户空间进程抢占内核线程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8453294/

相关文章:

c - : type_a sample; type_b *sample_b = (type_b *) ((void*) &sample); 中的无关(void *)

c - 无法理解 Atoi 函数 - *string - '0'

linux - 内核和正常进程

linux - Amazon EC2 实例可用磁盘空间差异

linux - 从一组文件 linux 中删除空格

充满垃圾的C文件

c - 内存分配问题

linux - 使用 AWK 将 float 转换为用户定义的输出

linux - 每 60 秒复制一个文件 bash

c - 如何在linux内核中找到中断源代码?