Guest User

Untitled

a guest
Jan 19th, 2012
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.37 KB | None | 0 0
  1. text = `ps -eo comm,rss`
  2.  
  3. #split the input into two colums: [progname,memusage]
  4. table=text.lines.collect {|l|  [l.split[0..-2].join ,l.split[-1].to_i/1024]}
  5.  
  6. # sort decrasing on the second field (memory usage)
  7. table.sort!{|x,y| y[1]<=>x[1]}
  8.  
  9. #format and print output
  10. puts table[0..4].inject("Memory usage (MB):\n"){|res,i|
  11.          res+=  i[0]+" ("+i[1].to_s+")"+" "
  12. }
Advertisement
Add Comment
Please, Sign In to add comment