Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl (http://www.velocityreviews.com/forums/f17-perl.html)
-   -   fork in perl 5.8.3 on windows (http://www.velocityreviews.com/forums/t24899-fork-in-perl-5-8-3-on-windows.html)

Josh Denny 03-02-2004 02:30 AM

fork in perl 5.8.3 on windows
 
I am trying to write a simple file transfer server in perl that will
reside of both windows and linux platforms. Basically, it accepts a
connection, forks a process, and then should close the child. on
windows, it dies after "accumulating" 64 children opened - however,
they should all (or most) have exited by that time. Any idea how to
get my children to exit and free up space for more connections?

Thanks - Josh

here's the relevant part of my code:


sub reaper { #to eliminate dead child processess
$waitpid=wait;
$SIG{CHLD}=\&reaper;
}
$SIG{CHLD}=\&reaper;

main();

sub main {
my $contentlength;

print "Loading data transfer server on port
$datatransfer_port...\n\n";
socket_listen (\*SERVER, $datatransfer_port);
while (accept ($client, SERVER)) {
my ($c_port, $c_iaddr) = sockaddr_in(getpeername($client));
my(@inetaddr) = unpack('C4', $c_iaddr);
my $from = join('.', @inetaddr);

if (my $pid = fork) { #if it is the server, then next
close $client or die "Client socket close failed: $!";
} elsif (defined $pid) { #a child
client_connect($client, $from); #processes the clients connection
exit(0);
} else {
die "fork error: $!"; #program dies here after 64
client_connect's
}
}
}

Will Stranathan 03-02-2004 03:08 PM

Re: fork in perl 5.8.3 on windows
 
josh.denny@vanderbilt.edu (Josh Denny) wrote in message news:<a3123321.0403011830.2f82de6d@posting.google. com>...
> windows, it dies after "accumulating" 64 children opened - however,
> they should all (or most) have exited by that time. Any idea how to
> get my children to exit and free up space for more connections?
>


This is probably not necessary - if the parent doesn't CARE when the
child dies, you ought to just be able to say:
$SIG{CHLD} = 'IGNORE';

> sub reaper { #to eliminate dead child processess
> $waitpid=wait;
> $SIG{CHLD}=\&reaper;
> }
> $SIG{CHLD}=\&reaper;


Take a look at client_connect and see why client_connect is hanging.
> while (accept ($client, SERVER)) {
> my ($c_port, $c_iaddr) = sockaddr_in(getpeername($client));
> my(@inetaddr) = unpack('C4', $c_iaddr);
> my $from = join('.', @inetaddr);
>
> if (my $pid = fork) { #if it is the server, then next
> close $client or die "Client socket close failed: $!";
> } elsif (defined $pid) { #a child
> client_connect($client, $from); #processes the clients connection
> exit(0);
> } else {
> die "fork error: $!"; #program dies here after 64
> client_connect's
> }
> }
> }


Jim Gibson 03-02-2004 11:24 PM

Re: fork in perl 5.8.3 on windows
 
In article <a3123321.0403011830.2f82de6d@posting.google.com >, Josh
Denny <josh.denny@vanderbilt.edu> wrote:

> I am trying to write a simple file transfer server in perl that will
> reside of both windows and linux platforms. Basically, it accepts a
> connection, forks a process, and then should close the child. on
> windows, it dies after "accumulating" 64 children opened - however,
> they should all (or most) have exited by that time. Any idea how to
> get my children to exit and free up space for more connections?
>
> Thanks - Josh
>
> here's the relevant part of my code:
>
>
> sub reaper { #to eliminate dead child processess
> $waitpid=wait;
> $SIG{CHLD}=\&reaper;
> }
> $SIG{CHLD}=\&reaper;
>
> main();
>
> sub main {
> my $contentlength;
>
> print "Loading data transfer server on port
> $datatransfer_port...\n\n";
> socket_listen (\*SERVER, $datatransfer_port);
> while (accept ($client, SERVER)) {
> my ($c_port, $c_iaddr) = sockaddr_in(getpeername($client));
> my(@inetaddr) = unpack('C4', $c_iaddr);
> my $from = join('.', @inetaddr);
>
> if (my $pid = fork) { #if it is the server, then next
> close $client or die "Client socket close failed: $!";
> } elsif (defined $pid) { #a child
> client_connect($client, $from); #processes the clients connection
> exit(0);
> } else {
> die "fork error: $!"; #program dies here after 64
> client_connect's
> }
> }
> }


My guess is that the client_connect routine is hanging up and not
returning, but without seeing the code it is really hard to tell. Print
out the PIDs in the parent and print the PID ($$) from the child just
before the exit(0) statement to tell for sure.

You might want to check out socket modules: Socket or IO::Socket.


All times are GMT. The time now is 01:46 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57