Last active
August 29, 2015 14:03
-
-
Save fire/8eaf3f9afa0da89eebb4 to your computer and use it in GitHub Desktop.
Smartos style ps process from bluepill
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def ps_axu | |
# TODO: need a mutex here | |
store[:ps_axu] ||= begin | |
if RbConfig::CONFIG["arch"] == "x86_64-solaris2.11" | |
lines = `ps -eo pid,ppid,pcpu,rss,etime,comm`.split("\n") | |
else | |
# BSD style ps invocation | |
lines = `ps axo pid,ppid,pcpu,rss,etime,command`.split("\n") | |
end | |
lines.inject(Hash.new) do |mem, line| | |
chunks = line.split(/\s+/) | |
chunks.delete_if {|c| c.strip.empty? } | |
pid = chunks[IDX_MAP[:pid]].strip.to_i | |
command = chunks.slice!(IDX_MAP[:command], chunks.length).join ' ' | |
chunks[IDX_MAP[:command]] = command | |
mem[pid] = chunks.flatten | |
mem | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment