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?
In reply to Taming multiple external processes by 87C751
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |