Greetings avout,

I have some bot (running on Linux) code using Bot::BasicBot. When I fork a search process it returns the data but there is no reply to the channel. Without forking the reply works. Why? I'm guessing that the child doesn't know something that the parent does, but I don't know what. I've cut down the code the relevant bits:

# Start the bot my $bot = Cfbot->new( %{ $c->{irc} } )->run; package Cfbot; use base 'Bot::BasicBot'; use Data::Dumper; my @kids; # # Subs that override Bot::BasicBot's own subs # sub said { # ... do stuff then call a forkit sup. $self->forkit( run => \&main::lookup_topics, arg => $keyword, msg => $msg ); } sub forkit { my $self = shift; my %args = @_; warn '%args '.Dumper( \%args ); my $msg = $args{msg}; warn 'self->{msg}'. Dumper( $self->{msg}); my $childpid = fork; if ( 0 == 0 ) # <<< fork disabled #if ( ! defined $childpid ) # <<< fork enabled { warn "Failed to fork, processing in foreground instead."; my $replies = $args{run}->( $args{arg} ); $self->reply( $msg, $_ ) foreach ( @{ $replies } ); # <<< WORKS } elsif ( 1 == 0 ) # <<< fork disabled #elsif ( $childpid == 0 ) # <<< fork enabled { # This is the child process my $replies = $args{run}->( $args{arg} ); warn 'Child $replies '. Dumper( \$replies ) if $args->{debug}; ##### # TODO why does this reply fail? ##### $self->reply( $msg, $_ ) foreach ( @{ $replies } ); # <<< FAILS exit 0; } else { # This is the parent process. # Keep record of kids to kill later and prevent zombies. push @kids, $childpid; waitpid $childpid, 0; } } END { kill 15, @kids }

Neil Watson
watson-wilson.ca


In reply to Fork in Bot::BasicBot fails to send reply by neilwatson

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.