Skip to content

Instantly share code, notes, and snippets.

@fire
Last active August 29, 2015 14:03
Show Gist options
  • Save fire/8eaf3f9afa0da89eebb4 to your computer and use it in GitHub Desktop.
Save fire/8eaf3f9afa0da89eebb4 to your computer and use it in GitHub Desktop.
Smartos style ps process from bluepill
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