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();
}
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.