Is there a way to get a process's child process status based on its PID in Ruby?
For example, in Python you can do psutil.Process(pid).status
Is there a way to get a process's child process status based on its PID in Ruby?
For example, in Python you can do psutil.Process(pid).status
On OS X, I setup a string:
then execute it in a %x call:
I can display that if needed, or just keep the output clean and act on the State I found with the call.
I don't know of a portable ruby method to get process state of a running process. You can do
Process.wait
and check$?.exitstatus
, but that doesn't look like what you want. For a posix solution, you could useto get the letter code ps produces for process state
I was looking for the same thing. It's a shame ProcessStatus doesn't seem to be able to get initialized from a live pid. This is vital stuff if you want to do anything like a safe timed kill of a child process.
In any case, it's the second line in
/proc/$pid/status
if you're on Linux.:status_line = File.open("/proc/#{pid}/status") {|f| f.gets; f.gets }
Most likely much much faster than anything involving an external program.