Hi all, well, I have another question now after trying to go with wog's idea of forking off a child before starting up my mainwindow in for tk (on win32).

My goal: To have a forked child just sit there waiting for commands to come in and when one comes in, do it. The commands will just be web page urls to go get and dump in a file. Ideally then the child could send on a reverse pipe a command to the parent saying the page is done.

I went to the IPC help page on perldoc.com and here was my (sad?) attempt at getting a child to wait. Just to point out, I am getting parent and child to both work in the standard "bidirectional communication" example from perldoc.com but here I'm trying to add to that to make the child wait for a readable file handle. Any help would really be appreciated.

#!/usr/bin/perl -w # pipe1 - bidirectional communication using two pipe pairs # designed for the socketpair-challenged use IO::Handle; # thousands of lines just for autoflush :-( use IO::Select; # thousands of lines just for autoflush :-( pipe(PARENT_RDR, CHILD_WTR); # XXX: failure? pipe(CHILD_RDR, PARENT_WTR); # XXX: failure? CHILD_WTR->autoflush(1); PARENT_WTR->autoflush(1); $sel = new IO::Select( PARENT_RDR ); if ($pid = fork) { close PARENT_RDR; close PARENT_WTR; print CHILD_WTR "Parent Pid $$ is sending this\n"; chomp($line = <CHILD_RDR>); print "Parent Pid $$ just read this: `$line'\n"; close CHILD_RDR; close CHILD_WTR; waitpid($pid,0); } else { die "cannot fork: $!" unless defined $pid; close CHILD_RDR; close CHILD_WTR; print PARENT_WTR "Before: Child Pid $$ is sending this\n"; while(@ready = $sel->can_read) { foreach $fh (@ready) { chomp($line = <$fh>); print "Child Pid $$ just read this: `$line'\n"; } } print PARENT_WTR "After: Child Pid $$ is sending this\n"; close PARENT_RDR; close PARENT_WTR; exit; }

Justin Eltoft

"If at all god's gaze upon us falls, its with a mischievous grin, look at him" -- Dave Matthews


In reply to IPC, trying for have child wait for commands by Eradicatore

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.