CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
Problem with socket prog using fork() and reconnect routine yeilding zombies.

 



qwerty
Deleted

Aug 25, 2000, 4:12 PM

Post #1 of 3 (2314 views)
Problem with socket prog using fork() and reconnect routine yeilding zombies. Can't Post

This program is called "rout2.pl"!!!! I am telling you this so the system() call makes sense. This program causes a zombie every time I have to reconnect after getting disconnected. The entire program actualy consists of 4 seperate processes working together with a total of two seperate perl progs talking through local loopback via sockets and one acting as a virtual harddrive so the entire network of 20 progs can read and right to it (this is cool cause now one can share variables between any number of processes or perl progs without sysV!). The virtual harddrive code is not listed. Stripped down code of perl prog #1 is listed below. I will send $1 to the first person who solves this problem. email me at neptron@mailcity.com . I just stripped down this code and it has not been tested yet but you'll get the basic idea. Thanks....


#!/usr/bin/perl
use IO::Socket;
$returnaddr="localhost";

&Begin;

sub Begin {


$server="192.168.100.20";
$port = "2346";

$remote = IO::Socket::INET->new(Proto=>"tcp", PeerAddr=>$server, PeerPort=>$port, LocalAddr=>$returnaddr, LocalPort=>$port, Reuse=>1);

if (!defined($remote)) {
&Noconnect;
}else{
print "-----I am connected on port: $port\n";
$remote->autoflush(1);
}
}

sub Noconnect {
print "Could not connect\n";
sleep 2;
&Begin;
}


#vcons request through server below#
$portb = 2345;
$maxconn = SOMAXCONN;
$server = IO::Socket::INET->new(Proto=>"tcp", LocalPort=>$portb, Listen=>$maxconn, Reuse=>1) or die "Can't setup server\n";
print "-----I receive all requests. Listening on port: $portb\n";


die "fork fail: $!" unless defined($kid = fork);
if ($kid) {


close $server;
my $buf;

while (sysread($remote, $buf, 1) == 1) {

print $buf . "\n";

}
close $remote;
# kill the child process. But this doesn't
#seem to happen?
kill(TERM => $kid);

#this where the zombies get created
#call to restart prog to reconnect
system('perl', "rout2.pl");
exit;
} else {
#forward all from vcons#
#this is who the zombie is, this guy doesn't get closed
#out when the system() call is called to restart the
#program
while($client = $server->accept){
$client->autoflush(1);
$in = <$client ; #html parser made me minus the greater
print $client "\n\n";
close $client;
chomp($in);
chomp($in);
print $remote "$in";


}
close $remote;
exit;
}


Note: All zombies disapear after ctrl+c`ing the final open rout2.pl prog.


Any info on calling a disconnect without ctrl+c`ing would also be great. this would most likely have to be done by sending a specific packet that means "disonnect" which would force the prog into a disconnect routine. I tried this but it failed with more zombies. Is there an ultimate way to just destroy all zombies at any given time?



qwerty
Deleted

Aug 28, 2000, 12:32 PM

Post #2 of 3 (2314 views)
Re: Problem with socket prog using fork() and reconnect routine yeilding zombies. [In reply to] Can't Post

I figured out that by replacing my reconnect command with:

kill(TERM => $kid);
waitpid($kid,0);
exec('perl', "rout3.pl");
exit;

results in no zombies. It needed to wait for the last instance of the child to exit before it exited itself.


erwanG
Deleted

Sep 21, 2000, 7:05 AM

Post #3 of 3 (2314 views)
Re: Problem with socket prog using fork() and reconnect routine yeilding zombies. [In reply to] Can't Post

I work on the same type of prog and I would like to kill the server from the client.
I fork the server each time a client connect.
I use signal handlers like $SIG{CHLD}.
I want to make something like this command:
client -kill => send a kill signal to the server and the server stop!
but the server never stops :-(
and i can still connect other clients!
(sorry for my language level but english is not my native language ;-))
If you have any idea...please post!
R1

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives