linux - 对 "kernel process"的疑问

标签 linux process kernel

实际上,我不太理解的概念之一是“内核进程”或内核线程。在网上搜索并在 SOO 中搜索类似问题时,我发现了以下内容:What is a Kernel thread?答案是:

A kernel thread is a kernel task running only in kernel mode

据我所知,进入“内核模式”的进程必须发出系统调用。所以我不明白这些线程是如何一直以这种模式运行的。有人可以帮助我理解这是如何工作的吗?

最佳答案

内核线程是只能由另一个内核线程创建的线程(已经处于“内核模式” - 也许某些驱动程序可以生成它们来对它们进行一些清理或监视),因此没有用户线程可以启动(并且使用系统调用切换上下文),并且这些线程在内核地址空间内启动,因此它们不需要任何额外的内容即可进入内核模式。

创建的内核线程与用户线程一样以正常优先级和调度程序功能运行。来自kthread_create_on_node(http://lxr.free-electrons.com/source/kernel/kthread.c#L269):

310         task = create->result;
311         if (!IS_ERR(task)) {
312                 static const struct sched_param param = { .sched_priority = 0 };
313                 va_list args;
314 
315                 va_start(args, namefmt);
316                 vsnprintf(task->comm, sizeof(task->comm), namefmt, args);
317                 va_end(args);
318                 /*
319                  * root may have changed our (kthreadd's) priority or CPU mask.
320                  * The kernel thread should not inherit these properties.
321                  */
322                 sched_setscheduler_nocheck(task, SCHED_NORMAL, &param);
323                 set_cpus_allowed_ptr(task, cpu_all_mask);
324         }

关于linux - 对 "kernel process"的疑问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32776994/

相关文章:

c++ - ethtool ioctl 返回未填充的 ethtool_link_settings

.net - 检查程序是否抛出异常

c# - 如何从命令行或 C# 应用程序检测 msbuild 的状态

c++ - 在 android 内核开发 linux 中使用蓝牙

linux - 打补丁后的内核编译

linux - 为什么我的 perl 系统命令不起作用?

在程序中检查网络状态和控制PPP

linux - 将编译标志附加到 Linux 内核构建

c++ - 回溯是如何工作的?

c - 子进程不读取 PIPE