in reply to subroutines which forks?

Should I fork twice, once to create a 'controller' child, which itself forks the 'worker' grandchildren?

fork isn't something I use much, but it strike me that forking twice so that the first level of fork can wait upon the second just moves the goalposts. You still have the problem of waiting for those first levels kids in the originator.

I guess you could use async:

for my $job ( @jobs ) { my $pid = fork // die 'fork failed'; if( $pid ) { async{ waitpid $pid; }->detach; } else { dojob( $job ); } }

Of course, then it might simply be easier to skip the forking completely:

for my $job ( @jobs ) { async \&dojob, $job; } while( threads->list( 1 ) ) { $_->join for threads->list( 0 ); }

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP an inspiration; A true Folk's Guy