code:kill - ikarishinjieva/unixV6-code-analyze-chs GitHub Wiki

Source

  • kill 的 系统调用函数
  • 向 指定进程 发送 指定信号
    • 若 指定进程号 为 0,信号发送给 当前进程同一终端上的所有进程
  • 共输入2个参数 pid , sig
    • pid : 指定进程号,保存在 u.u_ar0[R0]
    • sig : 指定信号,保存在 u.u_arg[0]

3629

3630 kill()

3631 {

3632     register struct proc *p, *q;

3633     register a;

3634     int f;

3635

3636     f = 0;

3637     a = u.u_ar0[R0];

3638     q = u.u_procp;

3639     for(p = &proc[0]; p < &proc[NPROC]; p++) {

3640          if(p == q)

3641           continue;

3642          if(a != 0 && p->p_pid != a)

3643           continue;

  • pid != 0 ,且 p 进程号不匹配 pid ,则继续
3644          if(a==0&&(p->p_ttyp!=q->p_ttyp||p<=&proc[1]))

3645           continue;

  • pid ==0,且
    • p 和 当前进程 不在同一终端,则继续
    • p 为 0# 1# 进程,则继续
3646          if(u.u_uid != 0 && u.u_uid != p->p_uid)

3647           continue;

  • 当前用户 不是 超级用户,且不是p的拥有者,则继续
3648          f++;

3649          psignal(p, u.u_arg[0]);

  • 发送信号
3650     }

3651     if(f == 0)

3652          u.u_error = ESRCH;

  • 若 未找到 匹配进程,则抛出错误
3653 }

3654 /* ------------------------- */

Ref

Param

(kill = 37.; not in assembler)
(process number in r0)
sys kill; sig
⚠️ **GitHub.com Fallback** ⚠️