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)