tobold.org

correct • elegant • free

△ comp.lang.perl △

◅ Storing objects into a tied hash

Notorious problem with sockets and POP3 - please give me a clue ▻

Cleaning up defunct processes on SunOS

In article <32F661B2.446B9B3D@research.att.com>,
Avi Rubin  <rubin@research.att.com> wrote:
>We are developing a multithreaded (many forks) application,
>and on an SGI machine, we use
>
>$SIG{CHLD} = \&REAPER;
>sub REAPER {
>my $waitedpid;
>    $waitedpid = wait;
>    logmsg "reaped $waitedpid". ($? ? " with exit $?" : "");
>}
>
>to get rid of defunct/zombie processes. It works great. However,
>when we go over to a sparcstation running SunOS 4.1.x, the
>program dies upon reaping the first child.

You can't do all that in a signal handler!

For portably reliable signal handlers, all you should do is set a global
variable and return.  Then in the main loop of your program, you can
check that variable, and take the appropriate action.  This is mentioned
in the perlipc(1) man page.

In this particular case, I wouldn't bother using signals.  Simply put
this code into your main loop somewhere.

    use POSIX 'WNOHANG';
    while (waitpid(-1, WNOHANG) > 0) {
            # do logging of $?, etc.
    }

Tim.
--
Tim Goodwin   | "A language needs both intestines and guts." -- Larry Wall

Original headers:

From: tim@pipex.net (Tim Goodwin)
Newsgroups: comp.lang.perl.misc
Subject: Re: Cleaning up defunct processes on SunOS
Date: 5 Feb 1997 13:53:13 GMT
Organization: UUNET PIPEX
Message-ID: <5da3c9$7mj@join.news.pipex.net>
References: <32F661B2.446B9B3D@research.att.com>

△ comp.lang.perl △

◅ Storing objects into a tied hash

Notorious problem with sockets and POP3 - please give me a clue ▻