help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] `eval' subprocess not terminated


From: Greg Wooledge
Subject: Re: [Help-bash] `eval' subprocess not terminated
Date: Thu, 6 Feb 2014 08:37:57 -0500
User-agent: Mutt/1.4.2.3i

On Thu, Feb 06, 2014 at 01:00:47AM +0200, Ion Savin wrote:
> From another terminal I kill the shell process:
> 
> $ kill -9 `ps h --format pid -C "test.sh"`
> 
> The shell process terminates but the child process is not killed.

This is because you're using SIGKILL (-9).  You could arrange for
your script to catch any other signal and kill the child and then
itself.  But SIGKILL can't be caught.  SIGKILL therefore leaves
a bloody mess every time you use it -- temporary files will be strewn
about, child processes will be left running, etc.

Don't use SIGKILL unless it's a dire emergency, and even then, it's
often better to reboot the entire system instead.


(test.sh)
#!/usr/bin/env bash
trap 'kill $child; kill $$' TERM
eval "whatever" & child=$!
wait


(interactive shell)
$ pkill test.sh



reply via email to

[Prev in Thread] Current Thread [Next in Thread]