in reply to how to use global vars after forking()

To expand what nikosv wrote: yes, I know this is stripped down example code - but in the child branch, you MUST exit

foreach my $hostname (@host) { my $thr = fork(); if($thr) { #parent push(@childsall, $thr); next; } else { connecttohost($hostname); exit; # <---- here } } foreach my $child_pid (@childsall) { my $tmp = waitpid($child_pid, 0); }

because otherwise each child resumes the loop at its current state, spawning child processes which spawn child processes which spawn child processes which spawn child processes which spawn...

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Replies are listed 'Best First'.
Re^2: how to use global vars after forking()
by gjoshi (Sexton) on Oct 16, 2015 at 08:43 UTC
    yes I am exiting in child branch. I got the answer. I can use IPC shareable and it works fine