killing a shell that has a running child shell

killing a shell that has a running child shell

Post by Sriram Karr » Tue, 12 Sep 2000 15:07:48



If I do something like:

Parent shell:> bash
bash-2.03$ ksh
$ tcsh

then if I find pid of bash and kill -9 it, the ksh and tcsh also
terminated (in a peculiar way.  I urge you to try it out.  They die in
"steps" i.e. if you do a ps as soon as you kill -9 the bash, you will
find the other two.  then if you press return or something, one of them
dies, and then the other after another return.  )

And sometimes, the parent shell from which it ( the first bash command)
was executed also gets nuked.

This behaviour appears to be quite peculiar to shells since other
programs seem to survive the killing of bash.

I am currently writing a shell (that "mimicks" the standards shells)
for a school project, and was wondering about this corner case.  I would
greatly appreciate if someone would shed some light on why this
happens.  Any pointers to relevant docs would also be greatly
appreciated.

thank you,
-karra

 
 
 

killing a shell that has a running child shell

Post by David Hasset » Wed, 13 Sep 2000 03:01:38



> If I do something like:

> Parent shell:> bash
> bash-2.03$ ksh
> $ tcsh

> then if I find pid of bash and kill -9 it, the ksh and tcsh also
> terminated (in a peculiar way.  I urge you to try it out.  They die in
> "steps" i.e. if you do a ps as soon as you kill -9 the bash, you will
> find the other two.  then if you press return or something, one of them
> dies, and then the other after another return.  )

You are fortuanate that they die at all! When you send signal 9 a
running program it CANNOT catch the signal and is terminated
immediately. This is a BAD thing. You should rarely kill programs with
'kill -9 pid' unless you are certain that no other signal are going to
pursude it to stop. Read:

http://www.ling.helsinki.fi/~reriksso/unix/award.html

For a whole page of things you should never do. ;-)

I would imagine the shells die in "steps" since they are well behaved
and check to see if their parent is still alive so they don't turn into
zombies or something.

Basically, to terminate a program, you should always send SIGTERM (15)
first, then SIGINT (2) then SIGHUP (1) - THEN, and only then, send
SIGKILL (9). That is why kill, by default, always sends SIGTERM if you
don't specify a signal.

Quote:> And sometimes, the parent shell from which it (the first bash command)
> was executed also gets nuked.

Precisely why you shouldn't use 'kill -9'. It's behaviour is
unpredictable. You have no idea which programs are currently relying on
programs started with other parents. </SLAP>

Quote:> This behaviour appears to be quite peculiar to shells since other
> programs seem to survive the killing of bash.

What a shame. They are obvoiusly not as well behaved as the shells.

Cheers,

Dave. :-)

 
 
 

1. killing a shell script is not killing child processes

dispatcher (NOHUP mode)->daemon->shell script (parent
PID)->executables(child PIDs)

When we try to kill shell script (parent PID) with kill-9 command, I
am expecting that all executables (child PIDs) that are running from
shell script should also be killed.

Shell script process is getting killed but not the child processes.

I tried read all the messages patiently but it added up more
confusions.

I found a way to kill all child processes before killing parent shell
script but trying to find a answer for this behaviour.

Any expert responses are welcome.

Cheers,
Srinivas

2. Help! Can you guess the problem with this server?

3. kernel 2.2.16-3 and aacraid

4. what is parent shell, child shell and subshell, ?

5. Linux Frequently Asked Questions with Answers (Part 2 of 6)

6. how to kill a child process that runs other children processes

7. re-partiton to get rid of windows

8. kill shell with its children

9. SEGV not killing child process of shell script

10. Bourne Shell script, that kills its child-processes?

11. Bourne Shell INTR kills children

12. Trying to run nohup from Korn shell but getting Bourne shell errors