Thanks for the pointer, I tried to follow the example as close as possible and came up with this (not proberly working) code:
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)


In reply to Re^3: How to do parallel processing within mod_perl by Anonymous Monk
in thread How to do parallel processing within mod_perl by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.