Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to know if a process is zombie?

3 views
Skip to first unread message

Iñaki Baz Castillo

unread,
Dec 26, 2009, 11:53:42 AM12/26/09
to
Hi, after some forks I need to know if a process still is alive or not, but in
case it's alive I also need to know if it's a zombie process (it died without
Process.wait or Process.detach).

Unfortunatelly I couln't find how to know it using Process module:
http://ruby-doc.org/core/classes/Process.html
http://ruby-doc.org/core/classes/Process/Status.html

Is there any other way to determine if a given PID is zombie?
Thanks.

--
Iñaki Baz Castillo <i...@aliax.net>

Robert Klemme

unread,
Dec 26, 2009, 12:51:47 PM12/26/09
to
On 26.12.2009 17:53, Iñaki Baz Castillo wrote:
> Hi, after some forks I need to know if a process still is alive or not, but in
> case it's alive I also need to know if it's a zombie process (it died without
> Process.wait or Process.detach).
>
> Unfortunatelly I couln't find how to know it using Process module:
> http://ruby-doc.org/core/classes/Process.html
> http://ruby-doc.org/core/classes/Process/Status.html
>
> Is there any other way to determine if a given PID is zombie?

I believe you can use Process.kill(0, suspicious_pid) and if you get
"Errno::ESRCH: No such process" it does not exist any more or is a
zombie. Then you can use Process.waitpid(suspicious_pid,
Process::WNOHANG) to end his martyrdom and get the exit code.

It's probably better to set up a signal handler though. But that
totally depends on your use case.

Kind regards

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

Iñaki Baz Castillo

unread,
Dec 26, 2009, 1:13:09 PM12/26/09
to
El Sábado, 26 de Diciembre de 2009, Robert Klemme escribió:
> On 26.12.2009 17:53, Iñaki Baz Castillo wrote:
> > Hi, after some forks I need to know if a process still is alive or not,
> > but in case it's alive I also need to know if it's a zombie process (it
> > died without Process.wait or Process.detach).
> >
> > Unfortunatelly I couln't find how to know it using Process module:
> > http://ruby-doc.org/core/classes/Process.html
> > http://ruby-doc.org/core/classes/Process/Status.html
> >
> > Is there any other way to determine if a given PID is zombie?
>
> I believe you can use Process.kill(0, suspicious_pid) and if you get
> "Errno::ESRCH: No such process" it does not exist any more or is a
> zombie.

Unfortunatelly I've already checked it and doesn't work since a zombie process
does exist and does receive signals, so Process.kill(0, suspicious_pid)
returns true.

Anyhow I found a better approach so now I don't need need to know if a process
is zombie.

Thanks a lot.

Robert Klemme

unread,
Dec 26, 2009, 1:50:01 PM12/26/09
to

Thank you for the heads up!

Bertram Scharpf

unread,
Dec 26, 2009, 2:19:03 PM12/26/09
to
Hi,

Am Sonntag, 27. Dez 2009, 01:53:42 +0900 schrieb Iñaki Baz Castillo:
> Hi, after some forks I need to know if a process still is alive
> or not, but in case it's alive I also need to know if it's a
> zombie process (it died without Process.wait or Process.detach).
>
> Unfortunatelly I couln't find how to know it using Process module:
>

> Is there any other way to determine if a given PID is zombie?

trap "SIGCHLD" do |sig| puts "A child became a zombie." end

This tells you when it happened. As far as I know there is no way
to find out which process it was. I recommend waiting
(Process.waitpid) for every pid you forked.

Bertram


--
Bertram Scharpf
Stuttgart, Deutschland/Germany
*
Discover String#notempty? at <http://raa.ruby-lang.org/project/step>.

Iñaki Baz Castillo

unread,
Dec 26, 2009, 3:07:18 PM12/26/09
to
El Sábado, 26 de Diciembre de 2009, Bertram Scharpf escribió:
> Hi,
>
> Am Sonntag, 27. Dez 2009, 01:53:42 +0900 schrieb Iñaki Baz Castillo:
> > Hi, after some forks I need to know if a process still is alive
> > or not, but in case it's alive I also need to know if it's a
> > zombie process (it died without Process.wait or Process.detach).
> >
> > Unfortunatelly I couln't find how to know it using Process module:
> >
> > Is there any other way to determine if a given PID is zombie?
>
> trap "SIGCHLD" do |sig| puts "A child became a zombie." end
>
> This tells you when it happened. As far as I know there is no way
> to find out which process it was. I recommend waiting
> (Process.waitpid) for every pid you forked.

Thanks a lot.

0 new messages