Mad_Mac has asked for the wisdom of the Perl Monks concerning the following question:
I am seeing some odd behavior from my code (below), and I'd like some help understanding it. My code is based off the Perl Cookbook Recipe 16.12.
When I first ran the code and hit CTRL C, the SIGINT killed all of the children processes, just like it was supposed to. Then I began having errors that said: cannot create semaphore. No space left on device or something very similar to that. In the process of debugging that, I noticed that CTRL-C no longer killed my child processes.
I'm still not sure I've completely understood what was causing me to run out of shared memory space, although my theory is: I was killing the code after just a few iterations, without using die. And I don't understand why my SIGINT trap isn't killing the child processes.
I appreciate any advice or help anyone can offer.
P.S. If it matters: I'm running this code on Linux Mint 9 and Perl 5.10.1
use strict; # use warnings; use Parallel::ForkManager; use LWP::Simple; use IPC::Shareable; my $max_forks = 100; my $forkman = Parallel::ForkManager->new( $max_forks ); my $count=0; my %data; open (URLS, "<url-list.txt"); my $count_handle = tie $count, 'IPC::Shareable', undef, {destroy => 1 +}; $SIG{INT} = sub { die "$$ dying\n" }; print "Parent PID is $$\n"; while( my $url = <URLS> ) { $forkman->start and next; chomp($url); fetch($url); $forkman->finish; } $forkman->wait_all_children; close URLS; print "\n\nDONE.\n"; sub fetch { #html get to test parallel forks my $target = shift; $count_handle->shlock(); my $thiscount = $count++; $count_handle->shunlock(); my @header = head("http://$target"); print "PID: $$, $thiscount: $target - @header\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Shared Memory and Child Processes
by JavaFan (Canon) on Oct 07, 2010 at 14:54 UTC |