X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/383318a4381375add624530005a803bd934ceec7..bdc143a7aa3f51a46eceec62b0b364599533fa21:/lunaix-os/kernel/process/sched.c diff --git a/lunaix-os/kernel/process/sched.c b/lunaix-os/kernel/process/sched.c index 91cf61b..82a2aa9 100644 --- a/lunaix-os/kernel/process/sched.c +++ b/lunaix-os/kernel/process/sched.c @@ -33,6 +33,8 @@ struct scheduler sched_ctx; struct cake_pile *proc_pile ,*thread_pile; +#define root_process (sched_ctx.procs[1]) + LOG_MODULE("SCHED") void @@ -256,7 +258,6 @@ __DEFINE_LXSYSCALL1(unsigned int, alarm, unsigned int, seconds) bed->alarm_time = seconds ? now + seconds : 0; - struct proc_info* root_proc = sched_ctx.procs[0]; if (llist_empty(&bed->sleepers)) { llist_append(&sched_ctx.sleepers, &bed->sleepers); } @@ -435,7 +436,7 @@ commit_process(struct proc_info* process) // every process is the child of first process (pid=1) if (!process->parent) { if (likely(!kernel_process(process))) { - process->parent = sched_ctx.procs[1]; + process->parent = root_process; } else { process->parent = process; } @@ -474,6 +475,20 @@ destory_thread(struct thread* thread) cake_release(thread_pile, thread); } +static void +orphan_children(struct proc_info* proc) +{ + struct proc_info *root; + struct proc_info *pos, *n; + + root = root_process; + + llist_for_each(pos, n, &proc->children, siblings) { + pos->parent = root; + llist_append(&root->children, &pos->siblings); + } +} + void delete_process(struct proc_info* proc) { @@ -520,6 +535,8 @@ delete_process(struct proc_info* proc) destory_thread(pos); } + orphan_children(proc); + procvm_unmount_release(mm); cake_release(proc_pile, proc);