- 论坛徽章:
- 3
|
原帖由 zx_wing 于 2008-12-28 14:54 发表
典型的断章取义,没把来龙去脉搞清楚就想当然了
Moreover, in order to keep process scheduling fair, the function shares the remaining timeslice of parent between the parent and the child (出自UL ...
When a new process is created, sched_fork( ), invoked by copy_process( ), sets the time_slice field of both current (the parent) and p (the child) processes in the following way:
p->time_slice = (current->time_slice + 1) >> 1;
current->time_slice >>= 1;
In other words, the number of ticks left to the parent is split in two halves: one for the parent and one for the child. This is done to prevent users from getting an unlimited amount of CPU time by using the following method: the parent process creates a child process that runs the same code and then kills itself; by properly adjusting the creation rate, the child process would always get a fresh quantum before the quantum of its parent expires. This programming trick does not work because the kernel does not reward forks. Similarly, a user cannot hog an unfair share of the processor by starting several background processes in a shell or by opening a lot of windows on a graphical desktop. More generally speaking, a process cannot hog resources (unless it has privileges to give itself a real-time policy) by forking multiple descendents.
If the parent had just one tick left in its time slice, the splitting operation forces current->time_slice to 0, thus exhausting the quantum of the parent. In this case, copy_process( ) sets current->time_slice back to 1, then invokes scheduler_tick( ) to decrease the field (see the following section).
这一段是英文原版的。我理解的意思是,一个父进程在创建一个子进程的时候,在第一次运行时,父子进程共享父进程剩余的时间片,直到他们用完时间片,进入过期队列。当第二次被调度的时候,那么他们才会拥有各自独立的时间片。我前面说的意思,指的是第一次被调度的情况,至于更深入的情况,确实没有细节的研究代码。
如果理解有错,zx_wing兄请多包涵。看来以后得慎言…… |
|