Script to kill defunct and zombie processes

Discussion in 'Perl Misc' started by Srini Vuggumudi, Apr 29, 2004.

  1. 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
     
    Srini Vuggumudi, Apr 29, 2004
    #1
    1. Advertising

  2. >>>>> "Srini" == Srini Vuggumudi <> writes:

    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
    --
    Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
    <> <URL:http://www.stonehenge.com/merlyn/>
    Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
    See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
     
    Randal L. Schwartz, Apr 29, 2004
    #2
    1. Advertising

  3. Srini Vuggumudi wrote:

    > 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?"
     
    Chris Mattern, Apr 30, 2004
    #3
  4. (Srini Vuggumudi) wrote in message news:<>...
    > 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;
    }



    > Thank you.
    >
    > Sincerely,
    >
    > Srini
     
    Bryan Castillo, Apr 30, 2004
    #4
  5. Bryan Castillo wrote:

    > (Srini Vuggumudi) wrote in message
    > news:<>...
    >> 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;
    > }
    >
    >

    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?"
     
    Chris Mattern, May 1, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gordon Beaton

    <defunct> processes

    Gordon Beaton, Oct 27, 2003, in forum: Java
    Replies:
    4
    Views:
    10,930
    Andrew
    Nov 7, 2003
  2. John Abel
    Replies:
    2
    Views:
    3,454
    John Abel
    May 12, 2005
  3. Replies:
    0
    Views:
    542
  4. serge.john.swilting

    plouk zombie plouk zombie

    serge.john.swilting, Aug 19, 2003, in forum: Perl Misc
    Replies:
    1
    Views:
    216
    hudson
    Aug 20, 2003
  5. Srini Vuggumudi

    Script to kill defunct and zombie processes

    Srini Vuggumudi, Apr 29, 2004, in forum: Perl Misc
    Replies:
    0
    Views:
    175
    Srini Vuggumudi
    Apr 29, 2004
Loading...

Share This Page