Guys,

I am running ActiveState Perl v5.8.0 straight out of the box, with the following test 
piece of code for forking and waiting for child processes. Perl.exe generates a GPF at 
0x0000000c as the child is quitting. Anyone have any ideas what might be going wrong? 
I based the code on the code extract within the fork documentation in the Camel book.

The output up until just before the GPF is as follows:

        Parent. Child is -108
        Child: started: -108
        Parent waiting for kiddies...
        Child: -108 about to exit.

Sorry if this topic has already been done to death, but I had a search and couldn't 
find anything that appeared relevant.

Ta.

Kev.


        sub InvokeCmdAsAsyncProcess
        {
                my( $exec_line, $dummy ) = @_;
                my $pid;

                FORK:
                {
                        if( $pid = fork ) {
                                # Parent process here.
                                # Child pid in $pid.
                                print "Parent. Child is $pid\n";
                        }
                        elsif( defined( $pid ) ) {
                                # Child process here.
                                # parent process pid is available with getppid
                                print "Child: started: $$\n";
                                sleep 10;
                                #system (1, "$exec_line");
                                print "Child: $$ about to exit.\n";
                                exit 0;
                        }
                        elsif( $! =~ /No more process/ ) {
                                # EAGAIN, supposedly recoverable fork error
                                print "Forking having problems. Retrying....\n";
                                sleep 2;
                                redo FORK;
                        }
                        else
                        {
                                # Wierd fork error.
                                die "Can't fork: $!\n";
                        }
                }

                return $pid;
        } # end of InvokeCmdAsAsyncProcess


        my %pids;
        my $pid;                # pid of most recent child process.
        foreach $filename (@files)
        {
                my $exec_line = "$filename > $filename.log";
                print "Executing $exec_line\n";
                $pid = InvokeCmdAsAsyncProcess( $exec_line );
                if( defined( $pid ) ) {
                        $pids{$pid} = $pid;
                }
        }

        print "Parent waiting for kiddies...\n";
        while( ($pid = wait()) != -1 ) {
                print "Parent: Child $pid exitted with status: $?\n";
        }
        print "Parent after wait.\n";




Kevin Hill
AVP Programmer
 
TradeWeb Europe Ltd 
99 Gresham Street
London EC2V 7NG
Tel:  +44 (0)20 7776 3200
Fax: +44 (0)20 7776 3201
www.tradeweb.com



________________________________________________________________________

This e-mail may contain confidential and/or privileged information. If you are not the 
intended recipient (or have received this e-mail in error) please notify the sender 
immediately and destroy this e-mail. Any unauthorized copying, disclosure or 
distribution of the material in this e-mail is strictly forbidden. TradeWeb reserves 
the right to monitor all e-mail communications through its networks.


_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to