在Ruby中通过pid获取进程状态

2024-03-25

有没有办法在 Ruby 中根据 PID 获取进程的子进程状态?

例如,在 Python 中,您可以执行 psutil.Process(pid).status


我不知道有一种可移植的 ruby​​ 方法来获取正在运行的进程的进程状态。你可以做Process.wait并检查$?.exitstatus,但这看起来不像你想要的。对于 posix 解决方案,您可以使用

`ps -o state -p #{pid}`.chomp

获取 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.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在Ruby中通过pid获取进程状态 的相关文章

随机推荐