在业务性能分析中,很多问题都是进程调度所引起。现特地总结进程调度子系统一些关键点,参考3.10内核源码。
task_struct
在Linux内核中,task_struct是对进程和线程的统一抽象,一个task_struct结构代表了一个进程或者线程。它也是之后调度器的基本单位,也就是说,对于调度器来说,进程和线程是同等的。
家族关系
- real_parent
fork进程时赋值一次。
static struct task_struct *copy_process(unsigned long clone_flags,
unsigned long stack_start,
unsigned long stack_size,
int __user *child_tidptr,
struct pid *pid,
int trace)
{
...
/* CLONE_PARENT re-uses the old parent */
if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
p->real_parent = current->real_parent;
p->parent_exec_id = current->parent_exec_id;
} else {
p->real_parent = current;
p->parent_exec_id = current->self_exec_id;
}
...
}
销毁进程时,把他的子进程的real_parent赋值一次。
static void forget_original_parent(struct task_struct *father)
{
...
list_for_each_entry_safe(p, n, &father->children, sibling) {
struct task_struct *t = p;
do {
t->real_parent = reaper;
if (t->parent == father) {
BUG_ON(t->ptrace);
t->parent = t->real_parent;
}
if (t->pdeath_signal)