1

On a normal day , when a process is killed , all its child processes must be attached to 'init' process (Great Grand-Daddy of all processes). Strangely , the XV6 doesn't seem to do so. Below is the code of 'kill' function in proc.c file in XV6

int kill(int pid)
{
struct proc * p;

acquire(&ptable.lock);

for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
    if(p->pid == pid){
        p->killed = 1;

        if(p->state == SLEEPING)
           p->state = RUNNABLE;
    release(&ptable.lock);
    return 0;
    }
}//end of for loop

release(&ptable.lock);
return -1;
}

Why isn't the killed process removed from the process table?
Why aren't its children adopted by 'init'?
And for God's sake, why is the killed process made RUNNABLE again ?

Daksh
  • 31
  • 1
  • 7
  • 1
    @JL2210 You're most probably wrong. To the OP: This is roughly the same in Linux and other modern Unices: `kill` doesn't kill a process outright, but command it to commit seppuku (which it will do at the first occasion instead of returning to user space), and if it's sleeping, it will wake it up in order to be able to do so. –  Sep 01 '19 at 13:52
  • 1
    The [comment](https://github.com/mit-pdos/xv6-public/blob/b818915f793cd20c5d1e24f668534a9d690f3cc8/proc.c#L476) just above that functions tells the same. The children adoption by init will [happen in `exit()`](https://github.com/mit-pdos/xv6-public/blob/b818915f793cd20c5d1e24f668534a9d690f3cc8/proc.c#L255) in the same source file. –  Sep 01 '19 at 13:58
  • @mosvy Good catch. Didn't notice that. – S.S. Anne Sep 01 '19 at 18:00

1 Answers1

3

In POSIX, to receive and handle a signal (terminating the process is handling a signal) a process must be scheduled. Before that time the signal is considered pending and the process still exists.

The child processes are probably orphaned when the process is actually terminated and removed from the kernel data structures.

Maxim Egorushkin
  • 131,725
  • 17
  • 180
  • 271