gpt4 book ai didi

linux - do_fork() 在哪里为新分配的 task_struct 定义了 "prio"字段?

转载 作者:太空宇宙 更新时间:2023-11-04 04:16:09 26 4
gpt4 key购买 nike

这包括其他字段,例如 static_prio 和策略。我知道根据定义,子进程从父进程继承它们,但是它发生在 do_fork() 的代码中的哪里?

最佳答案

新分配的task_struct的“prio”字段在sched_fork()函数中定义。sched_fork()函数的调用流程为fork() -> sys_fork() -> do_fork() -> copy_process() -> sched_fork()。

下面是 sched_fork() 函数供您引用。 (内核版本3.7.5)

void sched_fork(struct task_struct *p)
{
unsigned long flags;
int cpu = get_cpu();

__sched_fork(p);
/*
* We mark the process as running here. This guarantees that
* nobody will actually run it, and a signal or other external
* event cannot wake it up and insert it on the runqueue either.
*/
p->state = TASK_RUNNING;

/*
* Make sure we do not leak PI boosting priority to the child.
*/
p->prio = current->normal_prio;

/*
* Revert to default priority/policy on fork if requested.
*/
if (unlikely(p->sched_reset_on_fork)) {
if (task_has_rt_policy(p)) {
p->policy = SCHED_NORMAL;
p->static_prio = NICE_TO_PRIO(0);
p->rt_priority = 0;
} else if (PRIO_TO_NICE(p->static_prio) < 0)
p->static_prio = NICE_TO_PRIO(0);

p->prio = p->normal_prio = __normal_prio(p);
set_load_weight(p);

/*
* We don't need the reset flag anymore after the fork. It has
* fulfilled its duty:
*/
p->sched_reset_on_fork = 0;
}

.....
......
}

关于linux - do_fork() 在哪里为新分配的 task_struct 定义了 "prio"字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16324015/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com