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

Source

  • 跟踪 系统中,子进程进入SSTOP状态,响应跟踪请求

4009

4010 /*

4011  * Enter the tracing STOP state.

4012  * In this state, the parent is

4013  * informed and the process is able to

4014  * receive commands from the parent.

4015  */

4016 stop()

4017 {

4018     register struct proc *pp, *cp;

4019

4020 loop:

4021     cp = u.u_procp;

4022     if(cp->p_ppid != 1)

  • LIONS 源代码为4022     if(cp->p_pid != 1)
疑为笔误
4023          for (pp = &proc[0]; pp < &proc[NPROC]; pp++)

4024           if (pp->p_pid == cp->p_ppid) {

  • pp ← 现行进程的父进程
4025                wakeup(pp);

4026                cp->p_stat = SSTOP;

4027                swtch();

  • 唤醒 父进程
  • 子进程 置 SSTOP
  • 要求进程切换
  • 当 父进程 提出了跟踪请求,且子进程再次切换上台,继续执行
4028                if ((cp->p_flag&STRC)==0 || procxmt())

4029                     return;

  • 以下情况 函数返回
    • 子进程 STRC 被清 (不再进行跟踪)
    • 父进程 向 子进程 发送信号(procxmt() == 1)
4030                goto loop;

4031           }

4032     exit();

  • 以下情况 进程终止
    • 子进程 的 父进程 为 1#进程
(父进程 已经退出,子进程托管给1#进程) (已经没有必要继续跟踪了)
4033 }

4034 /* ------------------------- */

Ref

Caller

⚠️ **GitHub.com Fallback** ⚠️