Monks,
We recently had a problem with an external program that needs to be called with strings that may contain shell-metachars. After poking around a bit for the Right Way to do it, I found something like the following in the perlsec perldoc, for a nifty way to avoid the shell:
die "Can't fork: $!" unless defined $pid = open(KID, "-|"); if ($pid) { # parent while (<KID>) { # do something } close KID; } else { exec 'myprog', 'arg1', 'arg2' or die "can't exec myprog: $!"; }
I promptly adapted this method to my program, saw that it worked, and went on to the Next Task.
... time passes ...
While working on something else, my memory was jogged by something I read in perlipc:
Forking servers have to be particularly careful about cleaning up their dead children (called ``zombies'' in Unix parlance), because otherwise you'll quickly fill up your process table.
So... in the code above, does the parent need to wait() on the child? If not, why not?
Looking forward to hearing your wisdom...
--In reply to open(KID, "-|") and wait()? by edan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |