Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Ingoring Child Processes And glob()

by barndoor (Pilgrim)
on Jul 28, 2000 at 13:55 UTC ( #24818=perlquestion: print w/replies, xml ) Need Help??

barndoor has asked for the wisdom of the Perl Monks concerning the following question:

I have a bit of a chewy problem which has been giving me a headache all morning.

I've got a script which fork/execs child process which are then of no concern to the parent. I had this running fine apart from the children leaving themselves as zombies once they had completed.
After a quick read of the Cookbook I put in:
$SIG{CHLD} = "IGNORE";

Problem solved I thought, no more zombies and all is good in the world.
However when I reran the script I got the following messages:
glob failed (child exited with status -1, core dumped) at ./FeedsMonit +or.pl line 293 <_GEN_0> chunk 1.
I got three of these messages, 1 for each glob() in the script and with various chunk numbers. The globs themselves were still returning the right result but the messages were causing havoc as they went to the console even though this was running in background and with STDOUT and STDERR redirected to a logfile.
After doing more digging I found that glob() shells out to run itself. Therefore this is a child process and ignoring child signals seems to be causing the problem. Take the IGNORE out and back come the zombies but the messages go.
I've thought of reenabling the child signal handler to DEFAULT around the globs as below:
$SIG{CHLD}="DEFAULT"; @x = glob($globLine); $SIG(CHLD)="IGNORE";
However sooner or later one of my child processes is going to finish just a glob runs and will zombie itself.
Can anyone come up with a nice clean solution to this? I've not got a great deal of process/signal handling experience so any advice would be appreciated.

Replies are listed 'Best First'.
Re: Ingoring Child Processes And glob()
by merlyn (Sage) on Jul 28, 2000 at 16:43 UTC
      Thanks a lot. I went for the second option and it is just what I needed.
      Also had a reread of the Cookbook and found it there. Doh!
Re: Ignoring Child Processes And glob()
by barndoor (Pilgrim) on Jul 28, 2000 at 15:37 UTC
    Here some more of the script to give you an idea of what I'm doing:
    #!/usr/local/bin/perl -w use strict; sub executeStream($); $SIG{CHLD} = 'IGNORE'; # The glob below will work but the message detailed in my original pos +t will occur. my @fileList = glob("/mypath/*.log"); foreach my $logfile (@fileList) { print "Got logfile $logfile\n"; } executeStream(1); sub executeStream($) { my $childProcess; unless (defined($childProcess = fork())) { die "Could not fork new child process."; } unless($childProcess) { # Child process so lets exec the loader. exec("myprog " . $_[0]) or die "Could not exec FeedLoader.pl"; } }
Re: Ingoring Child Processes And glob()
by tye (Sage) on Jul 28, 2000 at 18:24 UTC

    You should probably follow some of the above advice even if you take my advice.

    Shelling out to do globbing really sucks so don't do it. Upgrade to a recent version of Perl and globbing is done internally. Alternately, grab one of the modules that does globbing in Perl and use them.

RE: Ingoring Child Processes And glob()
by barndoor (Pilgrim) on Jul 28, 2000 at 13:59 UTC
    By the way, I'm running on Solaris if that helps. And yes I know I can't spell Ignoring :-)
Re: Ingoring Child Processes And glob()
by c-era (Curate) on Jul 28, 2000 at 15:19 UTC
    I'm running solaris and I have not had any problems using glob and sig together. Could you post some more code so I can look at it more closely.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://24818]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2020-04-10 10:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The most amusing oxymoron is:
















    Results (49 votes). Check out past polls.

    Notices?