按名称查找进程 ID [英] Find a process ID by name
本文介绍了按名称查找进程 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 Ruby 中按名称或完整命令行查找 pid,而不调用外部可执行文件?
How can I find a pid by name or full command line in Ruby, without calling an external executable?
我将 SIGUSR2 发送到命令行包含 ruby job.rb
的进程.我想在不调用 pgrep
的情况下执行以下操作:
I am sending SIGUSR2 to a process whose command line contained ruby job.rb
. I would like to do the following without the call to pgrep
:
uid = Process.uid
pid = `pgrep -f "ruby job.rb" -u #{uid}`.split("\n").first.to_i
Process.kill "USR2", pid
推荐答案
一个快速的谷歌搜索想出了 sys_proctable,它应该让您以可移植的方式执行此操作.
A quick google search came up with sys_proctable, which should let you do this in a portable way.
免责声明:我不使用 Ruby,无法确认这是否有效.
Disclaimer: I don't use Ruby, can't confirm if this works.
这篇关于按名称查找进程 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文