in reply to Taming multiple external processes

Killing the shell process should send SIGHUP to its children. The default action for HUP is to terminate, but if it is not doing that you can set %SIG when you fork:

my $pid; { local $SIG{HUP} = $SIG{INT}; $pid = open2($rdhndl,$wrhndl,"app1 URL | app2") or die $!; }
What syntax are you using for kill? You certainly don't need to shell out to raise a signal in Perl.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: Taming multiple external processes
by 87C751 (Acolyte) on Jan 02, 2004 at 08:27 UTC
    I'm using kill 1, $pid;, and I've tried all of 1, 9, HUP, INT, SIGHUP, SIGINT and SIGKILL, all with the same result. Even setting local $SIG{HUP} = $SIG{INT}; made no change. Each time, app2 dies and the sh process becomes a zombie, but I still have 4 app1 processes. If I then kill the server that spawned them, all of the processes vanish.

    Here's a ps list after a client has connected:

    7314 pts/1 S 0:00 /usr/bin/perl -w ./testserver 7315 pts/1 S 0:00 sh -c ogg123 -q -d raw -f - http://cal.icec +ast.net:8630/prog1.ogg | lame --silent -b 320 -r - 7316 pts/1 S 0:00 ogg123 -q -d raw -f - http://cal.icecast.ne +t:8630/prog1.ogg 7317 pts/1 S 0:00 lame --silent -b 320 -r -x - - 7318 pts/1 S 0:00 ogg123 -q -d raw -f - http://cal.icecast.ne +t:8630/prog1.ogg 7319 pts/1 S 0:00 ogg123 -q -d raw -f - http://cal.icecast.ne +t:8630/prog1.ogg 7321 pts/1 S 0:00 ogg123 -q -d raw -f - http://cal.icecast.ne +t:8630/prog1.ogg

    After the client disconnects, the server does kill 1, $pid on the pid returned from open2. The ps list now looks like this:

    7314 pts/1 S 0:00 /usr/bin/perl -w ./testserver 7315 pts/1 Z 0:00 [sh] <defunct> 7316 pts/1 S 0:00 ogg123 -q -d raw -f - http://cal.icecast.ne +t:8630/prog1.ogg 7318 pts/1 S 0:00 ogg123 -q -d raw -f - http://cal.icecast.ne +t:8630/prog1.ogg 7319 pts/1 S 0:00 ogg123 -q -d raw -f - http://cal.icecast.ne +t:8630/prog1.ogg 7321 pts/1 S 0:00 ogg123 -q -d raw -f - http://cal.icecast.ne +t:8630/prog1.ogg

    You see that lame (my app2) is gone, and the shell is zombied. But all the ogg123 (app1) processes are still alive (and, according to the activity lights on the switch, still sucking data from the URL).

    Am I going mad?