4

I use htop to view information about the processes currently running in my osx machine, also to sort them by CPU, memory usage, etc.

Is there any way to fetch the output of htop programatically in Ruby?. Also I would like to be able to use the API to sort the processes using various parameters like CPU, memory usage, etc.

I can do IO.popen('ps -a') and parse the output, but want to know if there is a better way than directly parsing the output of a system command run programmatically.

4

1 回答 1

8

查看sys-proctable

require 'sys/proctable'

Sys::ProcTable.ps

排序方式starttime

Sys::ProcTable.ps.sort_by(&:starttime)
于 2014-03-29T14:13:44.873 回答