M
monk
Hi all, How can I fork off several children processes? sorry for the
dumb newbie question.
With this solution below, parent1() executes in parallel with
child1(), then parent2() executes in parallel with child2(), and so
on.
What I want is to have something like all parentX() subroutines
executing along with all childrenX() subroutines, all in parallel, all
together like a good family.
Is that possible?
This is what I have:
if ($pid = fork) {
print "processing parent subroutines\n";
parent1();
parent2();
parent3();
}
elsif (defined $pid) {
print "processing children subroutines\n";
child1();
child2();
child3();
exit(0);
}
else {
print "couldn't fork: $!\n";
}
#wait for children
waitpid($pid, 0);
print "Done with parent and children! \n";
exit 0;
dumb newbie question.
With this solution below, parent1() executes in parallel with
child1(), then parent2() executes in parallel with child2(), and so
on.
What I want is to have something like all parentX() subroutines
executing along with all childrenX() subroutines, all in parallel, all
together like a good family.
Is that possible?
This is what I have:
if ($pid = fork) {
print "processing parent subroutines\n";
parent1();
parent2();
parent3();
}
elsif (defined $pid) {
print "processing children subroutines\n";
child1();
child2();
child3();
exit(0);
}
else {
print "couldn't fork: $!\n";
}
#wait for children
waitpid($pid, 0);
print "Done with parent and children! \n";
exit 0;