Gorby has asked for the wisdom of the Perl Monks concerning the following question:

Hello Perl Monks. I'd like to know if there's a way a perl program can make sure that it does not linger in memory after it has completed running. My server administrator tells me that he sees a lot of my scripts "still out there but defunct". According to him, my scripts occupy memory even after they've finished running. I don't understand. Can you help me? Thanks a lot.

Replies are listed 'Best First'.
Re: Ending Properly
by Zaxo (Archbishop) on Feb 17, 2003 at 16:45 UTC

    That sounds like you are forking processes that end quickly, and not cleaning up afterwards. If so, wait, waitpid, or the special 'IGNORE' SIGCHLD handler will allow the system to release resources.

    If you show code...

    After Compline,
    Zaxo

Re: Ending Properly
by steves (Curate) on Feb 17, 2003 at 16:47 UTC

    A defunct process on UNIX is one that exits, but has no parent waiting on it to reap the process. So this probably has less to do with your Perl script than with the environment it's started in. Are you trying to background it, have it become a daemon, or running it from cron?

      Actually a defunct process does have a parent, but the parent has not collected the exit code from the child process. If the parent goes away, the child will be reparented to init, which will collect the exit code and allow the zombie to die.

        Ok. How do I make the parent go away? I'm not using fork or anything like that. All my scripts are designed to run straight from top to bottom. Thanks for your help.
Re: Ending Properly
by dbp (Pilgrim) on Feb 17, 2003 at 18:08 UTC

    Zombies...everywhere! Must reap dead children...

    Sorry, didn't sleep much and feeling pithy hackneyed.

      It would have been funny if NodeReaper had said it.