Script to kill defunct and zombie processes

S

Srini Vuggumudi

Hello Friends,

While browsing the messages in this new group, I found that a couple
of people tried and successful in cleaning the defunct and zombie
process using a PERL or shell script.

If you have a working script that cleans defuncts and zombies , could
you please post it? I appreciate your help. I do not have experience
with SIGNALS in PERL.

Also, here is my problem:

I have an apache/mysql/perl/Linux environment running cgis. My
webserver runs fine for a couple of days. After a month or so, it
starts running really slow (if someone try to access the URL, the
response will be slow). When the webserver responses are slow, If I do
ps -aef, I do see a lot of defunts. Aslo, if I do "top", I do see the
zombies count as 60 - 70. I believe these defunts and zombies may be
taking my webserver's resources and making it run slow.

Any suggesstions?

If you have a working script that cleans defuncts and zombies , could
you please post it? I appreciate your help.

Thank you.

Sincerely,

Srini
 
R

Randal L. Schwartz

Srini> While browsing the messages in this new group, I found that a
Srini> couple of people tried and successful in cleaning the defunct
Srini> and zombie process using a PERL or shell script.

A *defunct* or *zombie* process is a process that is already dead.
The only way for it to go away is for its parent to wait() for it. So
the problem cannot be solved unless the code of the program that is
issuing the fork() is changed. There are many techniques for this,
such as wait()ing for all kids at a choice point in a top-level loop,
or the famous "double fork" trick.

Also, no such thing as "PERL". Perhaps you mean "Perl" (or maybe even
"perl").

print "Just another Perl hacker,"; # the first
 
C

Chris Mattern

Srini said:
Hello Friends,

While browsing the messages in this new group, I found that a couple
of people tried and successful in cleaning the defunct and zombie
process using a PERL or shell script.

If you have a working script that cleans defuncts and zombies , could
you please post it? I appreciate your help. I do not have experience
with SIGNALS in PERL.

Also, here is my problem:

I have an apache/mysql/perl/Linux environment running cgis. My
webserver runs fine for a couple of days. After a month or so, it
starts running really slow (if someone try to access the URL, the
response will be slow). When the webserver responses are slow, If I do
ps -aef, I do see a lot of defunts. Aslo, if I do "top", I do see the
zombies count as 60 - 70. I believe these defunts and zombies may be
taking my webserver's resources and making it run slow.

Any suggesstions?

If you have a working script that cleans defuncts and zombies , could
you please post it? I appreciate your help.

Thank you.

Sincerely,

Srini

a) your zombies are not using any resources becuase zombies are just
processes that have terminated but still need to report their return
codes to their parents. Zombies never use *any* resources except a
slot in the process table, and 60 or 70 zombies aren't going to make
a significant impact on it.

b) You can't run a script to "clean" zombies; zombies are produced
by faulty code in the parent. They will *not* go away until the parent
collects their return code, normally by using some variety of wait().
You need to fix the code that forks these processes. If you're using
perl to create these processes, then the NG might be able to help you
debug it, but not until we see your code.

c) It's perl (or Perl for the language in the abstract), not PERL.
--
Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
 
B

Bryan Castillo

Hello Friends,

While browsing the messages in this new group, I found that a couple
of people tried and successful in cleaning the defunct and zombie
process using a PERL or shell script.

If you have a working script that cleans defuncts and zombies , could
you please post it? I appreciate your help. I do not have experience
with SIGNALS in PERL.

Also, here is my problem:

I have an apache/mysql/perl/Linux environment running cgis. My
webserver runs fine for a couple of days. After a month or so, it
starts running really slow (if someone try to access the URL, the
response will be slow). When the webserver responses are slow, If I do
ps -aef, I do see a lot of defunts. Aslo, if I do "top", I do see the
zombies count as 60 - 70. I believe these defunts and zombies may be
taking my webserver's resources and making it run slow.

Any suggesstions?

If you have a working script that cleans defuncts and zombies , could
you please post it? I appreciate your help.

This works, but I wouldn't suggest you use it :~)

use strict;
use warnings;
use IO::File;
my %bad_parents;

my $pipe = IO::File->new("ps -ef |") || die $!;
while (my $line = <$pipe>) {
if ($line =~ /^\S+\s+(\d+)\s+(\d+)\s+.*<defunct>/) {
my ($pid, $ppid) = ($1,$2);
print "Found zombie: $pid\n";
$bad_parents{$ppid} = 1;
}
}
$pipe->close;

while (my ($ppid,$val) = each %bad_parents) {
print "Killing $ppid\n";
kill KILL=>$ppid;
}
 
C

Chris Mattern

Bryan said:
(e-mail address removed) (Srini Vuggumudi) wrote in message


This works, but I wouldn't suggest you use it :~)

use strict;
use warnings;
use IO::File;
my %bad_parents;

my $pipe = IO::File->new("ps -ef |") || die $!;
while (my $line = <$pipe>) {
if ($line =~ /^\S+\s+(\d+)\s+(\d+)\s+.*<defunct>/) {
my ($pid, $ppid) = ($1,$2);
print "Found zombie: $pid\n";
$bad_parents{$ppid} = 1;
}
}
$pipe->close;

while (my ($ppid,$val) = each %bad_parents) {
print "Killing $ppid\n";
kill KILL=>$ppid;
}
Rather like dealing with a hangnail by taking an axe to the finger.
Solves the problem under consideration, but not likely to improve
the overall situation...
--
Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top