Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > fork in perl 5.8.3 on windows

Reply
Thread Tools

fork in perl 5.8.3 on windows

 
 
Josh Denny
Guest
Posts: n/a
 
      03-02-2004
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
}
}
}
 
Reply With Quote
 
 
 
 
Will Stranathan
Guest
Posts: n/a
 
      03-02-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) (Josh Denny) wrote in message news:<(E-Mail Removed). 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
> }
> }
> }

 
Reply With Quote
 
 
 
 
Jim Gibson
Guest
Posts: n/a
 
      03-02-2004
In article <(E-Mail Removed) >, Josh
Denny <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
os.fork and pty.fork Eric Snow Python 0 01-08-2009 06:32 AM
perl fork() problem: child exit() kills parent sunlight@gmail.com Perl Misc 4 11-29-2005 01:35 AM
Embedded perl - how to find out real PID after fork Andrew Zhilenko Perl 0 11-22-2004 07:11 AM
query on fork in perl debraj Perl Misc 3 05-25-2004 04:39 PM
Emacs debugger and perl fork Kelly Corcam Perl Misc 1 08-23-2003 01:43 PM



Advertisments