How to know if a process is zombie?

  • Thread starter Iñaki Baz Castillo
  • Start date
I

Iñaki Baz Castillo

R

Robert Klemme

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
 
I

Iñaki Baz Castillo

El S=E1bado, 26 de Diciembre de 2009, Robert Klemme escribi=F3:
=20
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 proc=
ess=20
does exist and does receive signals, so Process.kill(0, suspicious_pid)=20
returns true.

Anyhow I found a better approach so now I don't need need to know if a proc=
ess=20
is zombie.

Thanks a lot.



=2D-=20
I=F1aki Baz Castillo <[email protected]>
 
R

Robert Klemme

El Sábado, 26 de Diciembre de 2009, Robert Klemme escribió:

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.

Thank you for the heads up!

Kind regards

robert
 
B

Bertram Scharpf

Hi,

Am Sonntag, 27. Dez 2009, 01:53:42 +0900 schrieb I=F1aki 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).
=20
Unfortunatelly I couln't find how to know it using Process module:
=20
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


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

Iñaki Baz Castillo

El S=E1bado, 26 de Diciembre de 2009, Bertram Scharpf escribi=F3:
Hi,
=20
Am Sonntag, 27. Dez 2009, 01:53:42 +0900 schrieb I=F1aki Baz Castillo:
=20
trap "SIGCHLD" do |sig| puts "A child became a zombie." end
=20
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.

=2D-=20
I=F1aki Baz Castillo <[email protected]>
 

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,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top