473,387 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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
}
}
}
Jul 19 '05 #1
2 5736
jo********@vanderbilt.edu (Josh Denny) wrote in message news:<a3**************************@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
}
}
}

Jul 19 '05 #2
In article <a3**************************@posting.google.com >, Josh
Denny <jo********@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.
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: CwK | last post by:
How to use fork() system function to fork multi child process at the same time ? For example: Run a program to fork 5 child process at the same time and the parent must wait until all child...
0
by: Andrew Zhilenko | last post by:
Hello, Apparently Perl caches the value of the $$ variable (PID). So if it is a process with the embedded perl, and fork was performed not from within the Perl code, but by the C code 'outside'...
2
by: Allen Landsidel | last post by:
I have a job-processing backend written in perl, talking to a (of course) postgres database. The perl app has a master process that checks the database periodically for jobs that need processed. ...
0
by: rahulthathoo | last post by:
Hi, I have to call a perl program from within PHP, but since that program takes a long time to finish, i fork a process in my php code and then call the perl code, using exec. But I am not able...
5
by: JoeW | last post by:
Now before I go into detail I just want to say that this is purely for my own benefit and has no real world usage. I remember way back when the tool for *nix systems called forkbomb was created. I...
3
by: raghav82 | last post by:
For sending the message in linux environment- the perl script however uses fork() to release the client process as soon as possible and then in the child process handles the message send. For...
5
by: Jatek | last post by:
Hi i have learned how fork.pl and exec.pl work as a starting point,but i want to create a program called shell.pl that will repeatedly read a line of user inpu until the user enters CTRL-D (end of...
1
by: 3srt | last post by:
Hello, I created a simple 'server' script that will accept input from a cgi script. The server will handle multiple connections on the same port, also. In a nut shell, this 'server' script will...
0
by: lilly07 | last post by:
I tried a small example in perl forking. I opena connection with sql database in the parent or main program as follws: $dbh = DBI->connect("DBI:mysql:database=$database;host=$host", $user,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.