shijumic has asked for the wisdom of the Perl Monks concerning the following question:

I am new to perl and I was wondering what the following code does. Will this fork+socketpair works in perl windows environment. I need to write the same code in windows.
Is there any effective/alternative way I can do the same in windows?
May I know why it wont work in windows env?
The following is the code, Any help would be appreciated,Thanks..
if ($^O eq 'MSWin') { print("\nrunning directly from Windows is not supported -- Install + Cygwin\n\n"); exit(1); } my ($IO_FLAGS, $OS_MSWIN); BEGIN { ($IO_FLAGS, $OS_MSWIN) = (0, FALSE); # set any linux default values my $isWindows = FALSE; my $ioFlags = 0x00005421; if ($^O =~ m/win/i) { # change to win32 values $isWindows = TRUE; $ioFlags = 0x8004667e; } $processes=2; my $pid = fork(); for (my $i = 1; $i <= $processes; $i++) { my($child,$parent); socketpair($child,$parent,AF_UNIX,SOCK_STREAM,PF_UNSPEC) or die 'socketpair creation failure: '.$!; my $pid; if ($pid = fork) { close($parent); my @ary=(1); # non-blocking IO, compare to blocking "my @ary=(0);" my $val=pack("L",@ary); ioctl($child, $IO_FLAGS, $val); # we now have another child! we'll poll these later push @children, [ $child, $pid ]; push @pids, $pid; } else { debug 'child starting'; close($child); # kick off the child process childProcess($parent); close($parent); exit(); } }

Replies are listed 'Best First'.
Re: fork and socketpair
by Anonymous Monk on Apr 29, 2009 at 18:34 UTC
    Get rid of this
    if ($^O eq 'MSWin') { print("\nrunning directly from Windows is not supported -- Install + Cygwin\n\n"); exit(1); }
    and it will work on windows
Re: fork and socketpair
by dk (Chaplain) on May 04, 2009 at 09:06 UTC
    socketpair() will work, fork() won't. Either use threads or use Win32::Process module.
      fork will work, might be buggy but it will work