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...
|
|---|
| 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 |