This Windows fork() is a weird thing, because it uses threads to emulate what a Unix fork() would do.

I tried to write a simple scenario, but ran into problems with sleep(). My 'work-around' in the child process is not efficient, but it appears to work on Win XP, Perl 5.10.1.

I'd like to know a bit more about the application... The parent can send various flavors of "kill" to the child (you know its process id - and "kill" is basically a one bit message) and the child can have a signal handler to intercept this and figure out what to do. I don't see the need for any kind of "read" operation between the parent and the child, but maybe I don't understand what you need.

BrowserUk knows way more about communication between Windows threads than I do, but it doesn't sound like that is required? Setting up an IP connection between the client and the parent is possible, but I'm not sure of the need for that.

This is not a "server" it just forks a single child. More complex scenarios are possible.

#/usr/bin/perl -w use strict; my $pid = fork(); die "fork() failed: $!" unless defined $pid; if ($pid) { print "I am the child pid =$pid...\n"; while (1) { `ping 127.0.0.1 -n 5 > nul`; # sleep() won't work on Windows in multiple threads # the pid is a negative number and this a # thread (fork emulation) # there is Windows "weirdness" with sleep # here I started a command that will "wait" # for awhile before returning. # this is inefficent, but appears to work print "I am still the child ". localtime()."\n"; } } else { print "I am the parent\n"; while (sleep(2)) { print "I am still the parent ". localtime(), "\n"; } } __END__ C:\TEMP>perl client_server.pl I am the child pid =-5428... I am the parent I am still the parent Sat Aug 25 20:29:13 2012 I am still the parent Sat Aug 25 20:29:15 2012 I am still the child Sat Aug 25 20:29:16 2012 I am still the parent Sat Aug 25 20:29:17 2012 I am still the parent Sat Aug 25 20:29:19 2012 I am still the child Sat Aug 25 20:29:20 2012 I am still the parent Sat Aug 25 20:29:21 2012 I am still the parent Sat Aug 25 20:29:23 2012 I am still the child Sat Aug 25 20:29:24 2012 I am still the parent Sat Aug 25 20:29:25 2012 I am still the parent Sat Aug 25 20:29:27 2012 I am still the child Sat Aug 25 20:29:28 2012 I am still the parent Sat Aug 25 20:29:29 2012 Terminating on signal SIGINT(2) #I hit CTL-C in the command window... #the parent was running in the foreground...

In reply to Re: pipe fork win32 by Marshall
in thread pipe fork win32 by bulk88

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.