3.6:进程调度-退出

1:exit

程序退出处理程序

int do_exit(long code)

1)释放当前进程的代码段和数据段占的内存页

free_page_tables(get_base(current->ldt[1]),get_limit(0x0f));
free_page_tables(get_base(current->ldt[2]),get_limit(0x17));
 

2)如果当前进程有子进程,将该子进程的父进程设置位1号进程

for (i=0 ; i<NR_TASKS ; i++)
        if (task[i] && task[i]->father == current->pid) {
                task[i]->father = 1;
                if (task[i]->state == TASK_ZOMBIE)
                        /* assumption task[1] is always init */
                        (void) send_sig(SIGCHLD, task[1], 1);
        }

3)清空一些进程的工作状态,并设置当前进程位ZONBIE状态

for (i=0 ; i<NR_OPEN ; i++)
        if (current->filp[i])
                sys_close(i);
iput(current->pwd);
current->pwd=NULL;
iput(current->root);
current->root=NULL;
iput(current->executable);
current->executable=NULL;
if (current->leader && current->tty >= 0)
        tty_table[current->tty].pgrp = 0;
if (last_task_used_math == current)
        last_task_used_math = NULL;
if (current->leader)
        kill_session();
current->state = TASK_ZOMBIE;
current->exit_code = code;

4)向父进程发出SIGCHLD信号,终止该进程。重新调度

tell_father(current->father);
schedule();

2:kill

pid>0,信号发送给pid
pid=0,信号发送给当前进程组里的所有进程
pid=-1,sig就会发送给除第一个进程的所有进程
pid<-1,sig发送给出进程组-pid里的所有进程

int sys_kill(int pid,int sig)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值