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