in reply to pipe fork win32
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...
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: pipe fork win32
by BrowserUk (Patriarch) on Aug 26, 2012 at 06:49 UTC | |
by Marshall (Canon) on Aug 26, 2012 at 08:28 UTC | |
by bojinlund (Monsignor) on Aug 26, 2012 at 12:54 UTC | |
by bulk88 (Priest) on Aug 26, 2012 at 13:57 UTC | |
by BrowserUk (Patriarch) on Aug 26, 2012 at 14:40 UTC | |
by Marshall (Canon) on Aug 30, 2012 at 08:15 UTC | |
by BrowserUk (Patriarch) on Aug 26, 2012 at 14:11 UTC | |
by Marshall (Canon) on Aug 30, 2012 at 07:54 UTC | |
by bulk88 (Priest) on Aug 26, 2012 at 12:34 UTC | |
by BrowserUk (Patriarch) on Aug 26, 2012 at 14:05 UTC | |
by bulk88 (Priest) on Aug 26, 2012 at 15:10 UTC | |
by BrowserUk (Patriarch) on Aug 26, 2012 at 16:02 UTC |