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

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?

  • Comment on Re^4: fork - child executes code outside of block

Replies are listed 'Best First'.
Re^5: fork - child executes code outside of block
by tybalt89 (Monsignor) on Mar 28, 2018 at 19:53 UTC

    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.