How to do this depends on your operating system. Assuming Linux, you can manually scan the / proc file system and look for the correct command line. However, this is the same as pgrep does, and will actually make the program less portable.
Something like this might work.
def get_pid(cmd) Dir['/proc/[0-9]*/cmdline'].each do|p| if File.read(p) == cmd Process.kill( "USR2", p.split('/')[1] ) end end end
Just be careful looking in / proc.
AboutRuby
source share