87C751 has asked for the wisdom of the Perl Monks concerning the following question:
I need to control two external programs to accomplish a stream transcoding application. App 1 obtains its input from a URL and writes to STDOUT. It also forks 2-3 children. App 2 reads from STDIN and I read its output and send it on its way.
The good old open(FH,"app1 URL | app2 |"); performs the transcoding, but the catch is that I need to kill the children when the consumer quits drinking from my output. (recall that input is a stream... it doesn't end by itself) close(FH) doesn't seem to kill the kids (or even return, for that matter).
$pid = open2($rdhndl,$wrhndl,"app1 URL | app2"); also transcodes, but the PID returned is that of the sh process running the pipeline and killing that PID doesn't kill the children of App 1 (and indeed doesn't always kill App 1).
system("killall app1"); would work (sort of), but it's ugly, inefficient and doesn't allow for multiple clients of my transcoder.
Combining separate open2() calls hasn't worked. I can't seem to structure the calls so that App 2 reads from App 1's output without intermediation. (OK, I couldn't get it to work at all)
App 2 will die politely when its input disappears, so I really only need to reliably kill the first App 1 process.
What's a coder to do?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Taming multiple external processes
by Zaxo (Archbishop) on Jan 02, 2004 at 06:05 UTC | |
by 87C751 (Acolyte) on Jan 02, 2004 at 08:27 UTC | |
|
Re: Taming multiple external processes
by tilly (Archbishop) on Jan 02, 2004 at 08:06 UTC | |
by 87C751 (Acolyte) on Jan 02, 2004 at 09:36 UTC | |
by tilly (Archbishop) on Jan 02, 2004 at 15:56 UTC | |
by 87C751 (Acolyte) on Jan 02, 2004 at 20:25 UTC | |
by 87C751 (Acolyte) on Jan 02, 2004 at 08:47 UTC | |
|
Re: Taming multiple external processes
by sgifford (Prior) on Jan 02, 2004 at 09:56 UTC | |
by 87C751 (Acolyte) on Jan 02, 2004 at 21:06 UTC |