×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

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

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

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

(OP)
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 "\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 adisconnect 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?

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

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 "Zombies" for a more detailed explanation (which I should put in a faq, I know, I know)

Mike
michael.j.lacey@ntlworld.com
Cargill's Corporate Web Site

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

(OP)
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', "rout2.pl");
exit;


it just needed to wait for it to finish. Thanks for the reference, I'll have to check that out.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close