Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Zombie problem on reconnect - socket program with fork() , help needed

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
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 two seperate perl progs talking through local loopback via sockets and one acting as a virtual hard drive so the entire
network of 20 progs can read and right to it. The virtual hard drive code is not listed. Stripped down code of perl prog #1 is listed below. 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 &quot;\n\n&quot;;
close $client;
chomp($in);
chomp($in);
print $remote &quot;$in&quot;;


}
close $remote;
exit;
}


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


Any info on calling adisconnect without ctrl+c`ing would also be great. this would most likely have to be done by sending a specific packet that means &quot;disonnect&quot; 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?

 
Hi,

Unless you have a lot of zombies you probably don't seen to worry about them. Have a look at the TekTips HPUX forum

Home > Forum Areas > MIS > Operating Systems - UNIX based > HP: HP-UX Forum

And search for &quot;Zombies&quot; for a more detailed explanation (which I should put in a faq, I know, I know)
 
This program needs to run many years continuously. The server I connect to diconnects about ten times a day which would result in many zombies, restarting the program all the time is not an option. I figured it out none the less, it was actualy a pretty dumb thing to over look:


close $remote;
kill(TERM => $kid);
waitpid(0, $kid)
system('perl', &quot;rout2.pl&quot;);
exit;


it just needed to wait for it to finish. Thanks for the reference, I'll have to check that out.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top