如何从Ruby检查具有特定pid的进程是否正在运行? [英] How can I check from Ruby whether a process with a certain pid is running?

查看:142
本文介绍了如何从Ruby检查具有特定pid的进程是否正在运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有不只一种方法,请列出它们.我只知道其中一种,但是我想知道是否有一种更干净的Ruby方式.

If there is more than one way, please list them. I only know of one, but I'm wondering if there is a cleaner, in-Ruby way.

推荐答案

如果这是您希望拥有"的进程(例如,您正在使用它来验证您控制的进程的pid),则只需发送sig 0.

If it's a process you expect to "own" (e.g. you're using this to validate a pid for a process you control), you can just send sig 0 to it.

>> Process.kill 0, 370
=> 1
>> Process.kill 0, 2
Errno::ESRCH: No such process
    from (irb):5:in `kill'
    from (irb):5
>> 

这篇关于如何从Ruby检查具有特定pid的进程是否正在运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆