What you are seeing is exactly what I have seen trying to use fork() on a
Win32 system. In order to reliably use it, it has to be timed so that  all
threads are finished before any of them exit(), and using die causes the
whole script to die - not just the child PID.

What I've found to work better (on Win32 systems) is to either create a
separate script (instead of a subroutine), or set the script to call itself
with a flag field as an argument, and have the script check the @ARGV to see
how it is being called, and call the subroutine if the flags you are
expecting are set in $ARGV[0] (or whatever element you set the flag field
into).

When you set it up like that (I'll say we are calling a separate script -
that makes the explanation easier), you pass the data to the child process
by first setting up environment variables in the parent:

$ENV{remoteipaddress} = '10.17.100.100';
$ENV{remotesqlserver} = '10.20.100.100';

etc.

After you have the data set in the environment like you want, then open a
pipe for reading to the second script, and continue processing. Whenever you
are ready to get the data back, just read the pipe, and when you want that
process to complete before you continue, close that pipe:

open (PIPE1, "c:\\development\\myotherscript.pl |") || die "Couldn't open
PIPE1: $!\n";

# continue processing something else here.
# when you need the feedback from the PIPE1 process:

my $feedback;
{
  local $/ = undef;     # set slurp mode
  $feedback = <PIPE1>;
}
close PIPE1;

Anyway, that's just my suggestion ... maybe someone else has something a
little closer to what you are currently doing.

Hope this helps,

Steve H.


-----Original Message-----
From: Reiner Buehl [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, September 04, 2002 2:34 AM
To: [EMAIL PROTECTED]
Subject: LWP::UserAgent and fork() on Win32?


I know that fork() on Win32 is a experimental feature but maybe somebody
on the list can still help me: I am writing a script to request documents
from
a web server with multiple parallel clients. I would like to use fork() but
the 
moment the first child exits, the whole script dies. I tried creating the
UserAgent instance in a sub after forking and in the main routine still
before
the fork but the result is the same. Attached is a stripped down version of
my script. It works fine if only one child is used, but if set to two or
more,
it dies with a nasty windows memory fault.

Best regards,
Reiner. 

-- 
-- 
----------------------------------------------------------------------
Reiner Buehl                         Internet:
P.O. Box 100324                      [EMAIL PROTECTED]
70747 Leinfelden-Echterdingen 
Germany
---------------------------------------------------------------------- 

GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net
- This message (including any attachments) contains confidential information
intended for a specific individual and purpose, and is protected by law.  -
If you are not the intended recipient, you should delete this message and
are hereby notified that any disclosure, copying, or distribution of this
message, or the taking of any action based on it, is strictly prohibited.

Reply via email to