0

これには、static_prio や policy などの他のフィールドが含まれます。定義上、子プロセスがそれらを父親から継承することは知っていますが、 do_fork() のコードのどこで発生しますか?

4

1 に答える 1

0

新しく割り当てられた 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;
    }

    .....
    ......
}
于 2013-05-31T11:00:11.543 に答える