cyadav has asked for the wisdom of the Perl Monks concerning the following question:
Here's the code
#!/bin/perl -w my $pid = fork(); if ($pid) { print "PARENT --" . "\n"; waitpid(-1, 0) ; print "-- PARENT " . "\n"; } elsif ( $pid == 0 ) { print "CHILD --" . "\n"; } print "PID - $pid , MAIN PRG --" . "\n";
Child is able to execute this line of code print "PID - $pid , MAIN PRG --" . "\n"; - that it shouldn't be.
Here's the output -
Can you please explain ? Is something wrong here ? how to solve this ?PARENT -- CHILD -- PID - 0 , MAIN PRG -- -- PARENT PID - 53784 , MAIN PRG --
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: fork - child executes code outside of block
by hippo (Archbishop) on Mar 28, 2018 at 14:13 UTC | |
by cyadav (Initiate) on Mar 28, 2018 at 14:56 UTC | |
|
Re: fork - child executes code outside of block
by tybalt89 (Monsignor) on Mar 28, 2018 at 14:17 UTC | |
by ikegami (Patriarch) on Mar 28, 2018 at 18:47 UTC | |
by tybalt89 (Monsignor) on Mar 28, 2018 at 18:53 UTC | |
by ikegami (Patriarch) on Mar 28, 2018 at 19:38 UTC | |
by tybalt89 (Monsignor) on Mar 28, 2018 at 19:53 UTC | |
|