#!/usr/bin/perl use strict; use warnings; use Parallel::ForkManager; main(); sub main { my $pm = new Parallel::ForkManager(5); for (my $i=0; $i <= 10; $i++) { my $pid = $pm->start and next; print "Spawned process $$\n"; $pm->finish; } $pm->wait_all_children; }
Note: The child PID returns 0 inside parent but we can use the $$ special variable to get the PID of the child.
No comments:
Post a Comment