do_exit
调用exit的进程将成为僵尸进程,同时将为所有子进程寻找新的父进程,在ucore中将内核线程init作为新的父进程。
在linux中会实现寻找同进程组的进程来作为新的父进程,当找不到时在使用init。
// do_exit - called by sys_exit
// 1. call exit_mmap & put_pgdir & mm_destroy to free the almost all memory space of process
// 2. set process' state as PROC_ZOMBIE, then call wakeup_proc(parent) to ask parent reclaim itself.
// 3. call scheduler to switch to other process
int
do_exit(int error_code) {
if (current == idleproc) {
panic("idleproc exit.\n");
}
if (current == initproc) {
panic("initproc exit.\n");
}
struct mm_struct *mm = current->mm;
//如果是用户进程则释放占用用户空间
if (mm != NULL) {
//设置页目录表为内核线程的页目录表 防止cr3为空
lcr3(boot_cr3);
if (mm_count_dec(mm) == 0) {
exit_mmap(mm);
put_pgdir(mm);
mm_destroy(mm);
}
current->mm = NULL;
}
//设置为僵尸进程
curre

本文介绍了ucore操作系统中进程管理的关键函数do_exit、do_kill和do_wait。do_exit使得调用进程变为僵尸,子进程由内核线程init接管。do_kill通过设置进程标志来结束指定进程,而do_wait则负责等待并回收子进程的资源。
&spm=1001.2101.3001.5002&articleId=88844053&d=1&t=3&u=ea181ca16ee64130825cafaf0044d745)
3100

被折叠的 条评论
为什么被折叠?



