On Mon, Mar 28, 2011 at 06:59:23AM -0700, tytus64 wrote:
>
> Interesting...
> I used kill -HUP <pid> instead of killall -HUP <prog_name> and it works
> without interrupting the first loop. I also noticed 2 processes running when
> the first loop is iterating but only 1 when the second loop is iterating:
>
> $ ps -ef |grep <prog_name>
> bla 3711 2671 0 09:50 pts/0 00:00:00 /bin/bash ./<prog_name>
> bla 3714 3711 26 09:50 pts/0 00:00:01 /bin/bash ./<prog_name>
> bla 6739 2779 0 09:50 pts/1 00:00:00 grep <prog_name>
> $ ps -ef |grep <prog_name>
> bla 3711 2671 3 09:50 pts/0 00:00:00 /bin/bash ./<prog_name>
> bla 8461 2779 0 09:50 pts/1 00:00:00 grep <prog_name>
>
> It seems to me that "cat" in the first look is to blame. I probably receives
> SIGHUP but I am not sure about the rules of process naming: why <prog_name>
> instead of cat?
First point: process 3714 is a subshell. It's created because the code
you wrote required bash to spawn a subshell which implements your while
loop (not cat).
Second point: because you used killall <name>, you sent signals to
more than one process. You were killing the parent shell *and* the
subshell.
Third point: you aren't seeing the cat because your grep doesn't say
to show cat. Even if your grep did ask for cat in addition to <name>,
cat might already have finished by the time your ps|grep runs. It
depends on the size of the file, etc.