Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^3: fork - child executes code outside of block

by tybalt89 (Monsignor)
on Mar 28, 2018 at 18:53 UTC ( [id://1211939]=note: print w/replies, xml ) Need Help??


in reply to Re^2: fork - child executes code outside of block
in thread fork - child executes code outside of block

I just made the minimum change to fix the problem.

It's not my favorite way of doing fork, which is:

if( my $pid = fork ) { # parent } elsif( defined $pid ) { # child exit; } else { die "$! on fork"; }

Replies are listed 'Best First'.
Re^4: fork - child executes code outside of block
by ikegami (Patriarch) on Mar 28, 2018 at 19:38 UTC

    The question wasn't necessarily directed at you originally, but you showed that it applies to you too. Why do you arbitrarily split the parent code in three (partly before the if, partly in the if, partly after the if)? And why do you hide the error handling code far from where the error code occurred?

      To me fork() is essentially a three way branch or switch. I enclose all three parts in the same statement.

        No you didn't; execution falls through. You're missing an exit in the parent branch.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-19 05:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found