Search code examples
ruby

How to get information on a process (not the current process)


Is there a Ruby module or class that gives information about a currently running process that is not the current process? For example, if I have pid 1234, I'd like to get information on the user of the process, time, etc. I could get this information by shelling out to ps, but I would prefer getting the info from Ruby. For example, something like this made-up code:

require 'process/info'
process = ProcessInfo.new(1234)
puts process.pid
puts process.user

Any help in appreciated.


Solution

  • You could use the sys-proctable gem (which supports multiple OSs):

    require 'sys/proctable'
    
    process = ProcTable.ps(pid: 1234)
    puts process.uid