Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: fork() interferring with backtick

by vsespb (Hermit)
on Oct 16, 2013 at 17:11 UTC ( #1058505=note: print w/ replies, xml ) Need Help??


in reply to fork() interferring with backtick

why would the fork() interfere with the results from the backticks in line 8?
It could, if you'd have your own SIG{CHLD} handler, but you don't.

In second your example you are performing 1 fork call per @dir entry, and in first for each @dir entry * each @makelist entry

So those two examples are completelly different

I would suggest to minimize it to proof-of-concept code, so everyone could reproduce problem:
Remove `find ...` call, use `cat somefile` insted, don't use directory traversal. Minimize the code so it don't do anything unrelated to fork.


Comment on Re: fork() interferring with backtick
Re^2: fork() interferring with backtick
by mkaiser67 (Initiate) on Oct 16, 2013 at 18:37 UTC
    Actually I do have a SIG{CHLD} handler. It occurs before the code block:
    my $queue = []; sub REAP { my $kidpid; while(($kidpid = waitpid(-1,WNOHANG)) > 0) { #p rint "reaped $kidpid\n"; push @$queue, [ $kidpid, $? ]; } } $SIG{'CHLD'} = \&REAP;
    i didn't include it earlier thinking it didn't matter
      REAP called for external programs called with backtricks, however it seems it does not affect anything in your case.
      my $queue = []; sub REAP { my $kidpid; print STDERR "HANDLER\n"; while(($kidpid = waitpid(-1,WNOHANG)) > 0) { print STDERR "reaped $kidpid\n"; push @$queue, [ $kidpid, $? ]; } print STDERR "/HANDLER\n"; } $SIG{'CHLD'} = \&REAP; `echo 1`; my $pid = fork(); print STDERR "FORK CHILD $pid\n" if $pid; exit unless ($pid); print STDERR "before sleep\n"; sleep 2; print STDERR "after sleep\n"; print STDERR "DONE\n"; __END__ HANDLER /HANDLER FORK CHILD 29104 before sleep HANDLER reaped 29104 /HANDLER after sleep DONE
        I think my problem has to do with http://www.perlmonks.org/?node_id=1026468 I'm running 5.14 - my system hasn't been upgraded yet

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2014-08-28 00:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (253 votes), past polls