in reply to Re^2: How to do parallel processing within mod_perl
in thread How to do parallel processing within mod_perl
sub metasearch { my $self = shift; my $db_ref = $self->db_defs; my @dbs = @{$self->dbs}; my $logger = $self->logger; $SIG{CHLD} = 'IGNORE'; my @result; foreach my $db (@dbs) { defined (my $kid = fork) or die "Cannot fork: $!\n"; $logger->debug("Processing $db in process $kid"); if ($kid) { $logger->debug("Parent $$ has finished, kid's PID: $kid"); } else { # $r->cleanup_for_exec(); # untie the socket open STDIN, '/dev/null' or die "Can't read /dev/null: $!"; open STDOUT, '>/dev/null' or die "Can't write to /dev/null +: $!"; open STDERR, '>/tmp/log' or die "Can't write to /tmp/log: + $!"; # setsid or die "Can't start a new session: $!"; my $oldfh = select STDERR; local $| = 1; select $oldfh; warn "started\n"; sleep 1, warn "$_\n" for 1..20; warn "completed\n"; push @result, "simulate result for $db in $kid"; CORE::exit(0); # terminate the process } $logger->debug("End of $db"); } $logger->debug(join(', ', @result)); }
The difference is a foreach around the forks and the attempt to collect some result from the forked processes in @result but @result is empty.
What am I doing wrong?
As a side-note since I am not really interested in the warn-output: /tmp/log is empty after the run. Does this indicate that the child(s) didn't run?
I left out the cleanup_for_exec and the setsid lines because from the explanation I gathered they are not necessary in my situation and I didn't know if cleanup_for_exec call is still the same in mod_perl2 (the example is for mod_perl1)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: How to do parallel processing within mod_perl
by perrin (Chancellor) on Nov 14, 2007 at 13:51 UTC | |
by Anonymous Monk on Nov 14, 2007 at 14:43 UTC | |
by erroneousBollock (Curate) on Nov 15, 2007 at 14:13 UTC | |
by perrin (Chancellor) on Nov 15, 2007 at 14:57 UTC | |
by erroneousBollock (Curate) on Nov 15, 2007 at 15:20 UTC | |
|