eta*_*ang 5 ruby process-management
有没有办法根据Ruby中的PID来获取进程的子进程状态?
例如,在Python中,您可以执行psutil.Process(pid).status
我不知道有一种可移植的 ruby 方法来获取正在运行的进程的进程状态。您可以执行Process.wait并检查$?.exitstatus,但这看起来不像您想要的。对于 posix 解决方案,您可以使用
`ps -o state -p #{pid}`.chomp
Run Code Online (Sandbox Code Playgroud)
获取 ps 为进程状态生成的字母代码
PROCESS STATE CODES
Here are the different values that the s, stat and state output specifiers
(header "STAT" or "S") will display to describe the state of a process.
D Uninterruptible sleep (usually IO)
R Running or runnable (on run queue)
S Interruptible sleep (waiting for an event to complete)
T Stopped, either by a job control signal or because it is being traced.
W paging (not valid since the 2.6.xx kernel)
X dead (should never be seen)
Z Defunct ("zombie") process, terminated but not reaped by its parent.
Run Code Online (Sandbox Code Playgroud)