Linux调度程序是否愿意在fork()之后运行子进程? [英] Does the Linux scheduler prefer to run child process after fork()?
问题描述
Linux调度程序是否愿意在fork()
之后运行子进程而不是运行父进程?
Does the Linux scheduler prefer to run the child process after fork()
to the father process?
通常,分叉的进程将执行某种exec
,因此,最好让子进程在父进程之前运行(以防止写入时复制).
Usually, the forked process will execute exec
of some kind so, it is better to let child process to run before father process(to prevent copy on write).
我假设孩子将在创建后执行exec
作为第一个操作.
I assume that the child will execute exec
as first operation after it will be created.
我的假设(调度程序将首选子进程)是否正确.如果没有,为什么?如果是,那么还有其他理由要先运行孩子吗?
Is my assumption (that the scheduler will prefer child process) correct. If not, why? If yes, is there more reasons to run child first?
推荐答案
引用
在 After a 该书继续介绍内核版本的差异,并提到了CFS/Linux 2.6.32: The book goes on about the differences in kernel versions and also mentions CFS / Linux 2.6.32: [...]自Linux 2.6.32起,默认情况下,它再次是父级,在 [...] since Linux 2.6.32, it is once more the parent that is, by default, run first after a CFS仍然存在此行为,尽管有一些担忧此功能的未来.查看CFS实施,它似乎要安排父母先于孩子. This behaviour is still present with CFS although there are some concerns for the future of this feature. Looking at the CFS implementation, it seems to schedule the parent before the child. 适合您的方法是将 The way to go for you would be to set 编辑:此答案分析默认行为并将其与 This answer analyzes the default behaviour and compares it to 这篇关于Linux调度程序是否愿意在fork()之后运行子进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!fork()
之后,不确定哪个进程(父进程或子进程)接下来可以访问CPU. (在多处理器系统上,它们都可以同时访问CPU.)
fork()
, it is indeterminate which process - the parent or the child - next has access to the CPU. (On a multiprocessor system, they may both simultaneously get access to a CPU.)
fork()
之后首先运行.可以通过为Linux特定的/proc/sys/kernel/sched_child_runs_first
文件分配一个非零值来更改此默认值.
fork()
. This default can be changed by assigning a nonzero value to the Linux-specific /proc/sys/kernel/sched_child_runs_first
file./proc/sys/kernel/sched_child_runs_first
设置为非零值./proc/sys/kernel/sched_child_runs_first
to a non-zero value.sched_child_runs_first
进行比较. sched_child_runs_first
.