use threads; our @lparList = (); my @jobs = (); my $timeOut=1; # ... fill lparList from file, 1 array element per line. # (Line can consist of 1 or more , separated lparsnames sub manageLPAR ($$) { my $action = shift; my @LPARs=split (',',$_[0]); my $die = 0; print("Thread ",threads->self->tid(), " Started.\n"); $SIG{ALRM} = sub { print("Thread ",threads->self->tid(), " got SIGALRM.\n"); $action =~ s/^S/s/; print("Timeout in $action"); if ( $action eq "stop" ) { print("p"); } print("ing @LPARs. Good bye.\n"); $die = 1; #return; threads->exit(); #die "Got SIGALRM in stopLPAR Good bye.\n"; }; ... do stuff print("Thread ",threads->self->tid(), " Finished normally.\n"); } # main foreach $lpar ( @lparList ) { push @jobs, threads->create( sub { threads->yield(); manageLPAR ($action,$lpar); }); } # Wait $timeOut seconds for thread to finish. # kill thread when time is passed. $SIG{ALRM} = sub { foreach my $job (@jobs) { if ($job->is_running) { $job->kill('ALRM'); } } }; alarm($timeOut); # Wait for all jobs to finish or timeout $_->join for @jobs; # Wait for everything to finish.