-
-
Notifications
You must be signed in to change notification settings - Fork 33
Home
Daniel Berger edited this page Dec 26, 2022
·
7 revisions
The sys-proctable library provides a common interface for gathering process table information on different operating systems. You can determine which processes are running on your system, and details about those processes.
gem install sys-proctable
On version 1.1.5 or earlier, it may be necessary to specify a platform:
gem install sys-proctable --platform mswin32 # Windows
gem install sys-proctable --platform darwin # OS X
gem install sys-proctable --platform linux # Linux
gem install sys-proctable --platform sunos # Solaris
gem install sys-proctable --platform freebsd # FreeBSD
gem install sys-proctable --platform hpux # HP-UX
On version 1.1.5 or earlier, you may need to configure Bundler to install the proper version of sys-proctable:
bundle config specific_platform true
Otherwise, you may get an error or the code for the wrong OS.
- Linux
- FreeBSD
- DragonflyBSD
- OS X (Darwin 10.7 or later)
- MS Windows (Windows 7 or later)
- Solaris (SunOS 2.8 or later)
- AIX (5.3 or later)
Support for HP-UX was dropped in version 1.2. If you still need it, just install version 1.1.5 or earlier.
require 'awesome_print'
require 'sys/proctable'
Sys::ProcTable.ps{ |process|
ap process
}
# Sample output from OS X
{
:flags => 20987952,
:status => 2,
:xstatus => 0,
:pid => 2781,
:ppid => 1,
:uid => 501,
:gid => 20,
:ruid => 501,
:rgid => 20,
:svuid => 501,
:svgid => 20,
:rfu1 => 0,
:comm => "Vim",
:name => "Vim",
:nfiles => 25,
:pgid => 2781,
:pjobc => 0,
:tdev => 4294967295,
:tpgid => 0,
:nice => 0,
:start_tvsec => 1468938207,
:start_tvusec => 202961,
:virtual_size => 2643132416,
:resident_size => 15933440,
:total_user => 112080153,
:total_system => 30060156,
:threads_user => 109974372,
:threads_system => 27168589,
:policy => 1,
:faults => 4434,
:pageins => 0,
:cow_faults => 268,
:messages_sent => 1175,
:messages_received => 515,
:syscalls_mach => 1867,
:syscalls_unix => 3912,
:csw => 574,
:threadnum => 2,
:numrunning => 0,
:priority => 31,
:cmdline => "Vim -f -g -g test.rb",
:exe => "/Applications/MacVim.app/Contents/MacOS/Vim",
:environ => {
"RBENV_VERSION" => "2.3.1",
"TERM_PROGRAM" => "Apple_Terminal",
"SHELL" => "/bin/bash",
"TERM" => "xterm-256color",
"TMPDIR" => "/var/folders/kp/jdjh1k8504jbn2sxx63vslwm0000gn/T/",
"Apple_PubSub_Socket_Render" => "/private/tmp/com.apple.launchd.fKF6y7dARt/Render",
"TERM_PROGRAM_VERSION" => "361.1",
"TERM_SESSION_ID" => "BDC09E8B-CE85-4A5A-A850-53CB4F126091",
"USER" => "dberger",
"SSH_AUTH_SOCK" => "/private/tmp/com.apple.launchd.kStBvd1M96/Listeners",
"__CF_USER_TEXT_ENCODING" => "0x1F5:0x0:0x0",
"PATH" => "/Users/dberger/.rbenv/shims:/Users/dberger/.rbenv/bin:/usr/local/opt/ruby/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/TeX/texbin",
"PWD" => "/Users/dberger/Dev/sys-proctable",
"LANG" => "en_US.UTF-8",
"XPC_FLAGS" => "0x0",
"RBENV_SHELL" => "bash",
"XPC_SERVICE_NAME" => "0",
"SHLVL" => "1",
"HOME" => "/Users/dberger",
"LOGNAME" => "dberger",
"DISPLAY" => "/private/tmp/com.apple.launchd.OZvR9MxiYW/org.macosforge.xquartz:0",
"SECURITYSESSIONID" => "186a8",
"VIM" => "/Applications/MacVim.app/Contents/Resources/vim",
"VIMRUNTIME" => "/Applications/MacVim.app/Contents/Resources/vim/runtime"
},
:threadinfo => [
[0] {
:user_time => 109067000,
:system_time => 22207000,
:cpu_usage => 0,
:policy => 1,
:run_state => 3,
:flags => 1,
:sleep_time => 0,
:curpri => 31,
:priority => 31,
:maxpriority => 63,
:name => ""
},
[1] {
:user_time => 907000,
:system_time => 4961000,
:cpu_usage => 0,
:policy => 1,
:run_state => 3,
:flags => 1,
:sleep_time => 0,
:curpri => 31,
:priority => 31,
:maxpriority => 63,
:name => ""
}
]
}