Linux调度程序是否愿意在fork()之后运行子进程? [英] Does the Linux scheduler prefer to run child process after fork()?

查看:97
本文介绍了Linux调度程序是否愿意在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?

推荐答案

引用

fork()之后,不确定哪个进程(父进程或子进程)接下来可以访问CPU. (在多处理器系统上,它们都可以同时访问CPU.)

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

该书继续介绍内核版本的差异,并提到了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起,默认情况下,它再次是父级,在fork()之后首先运行.可以通过为Linux特定的/proc/sys/kernel/sched_child_runs_first文件分配一个非零值来更改此默认值.

[...] since Linux 2.6.32, it is once more the parent that is, by default, run first after a fork(). This default can be changed by assigning a nonzero value to the Linux-specific /proc/sys/kernel/sched_child_runs_first file.

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.

适合您的方法是将/proc/sys/kernel/sched_child_runs_first设置为非零值.

The way to go for you would be to set /proc/sys/kernel/sched_child_runs_first to a non-zero value.

编辑:此答案分析默认行为并将其与sched_child_runs_first进行比较.

This answer analyzes the default behaviour and compares it to sched_child_runs_first.

这篇关于Linux调度程序是否愿意在fork()之后运行子进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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