It really feels messy and not clear. Also, it is not the most efficient because ALL of the 15 calls are not depend one on another. with that logic I can create 15 if-else statements but of course it is not readable and clear. Also, the names are not the same (and all of them gets arguments - I removed them so it will be more easy to see). How should I solve it? Also, should I kill the child process when its done by using exit?my $forks = 0; foreach my $i (1..3) { if ($i == 1 && fork() == 0) { $forks++; print "Running first with $$ \n"; call_sub1(); call_sub2(); call_sub3(); call_sub4(); call_sub5(); call_sub6(); exit; } elsif ($i == 2 && fork() == 0) { $forks++; print "Running second $$ \n"; call_sub1(); call_sub10(); call_sub3(); call_sub13(); call_sub5(); exit; } else { if (fork() == 0) { $forks++; print "Running third with $$ \n"; call_sub1(); call_sub4(); call_sub5(); call_sub15(); exit; } } } for (1 .. $forks) { my $pid = wait(); print "Parent saw $pid exiting\n"; } print "done\n";
In reply to Re: Learning to use fork()
by ovedpo15
in thread Learning to use fork()
by ovedpo15
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |