Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- text = `ps -eo comm,rss`
- #split the input to two colums
- table=text.lines.collect {|l|
- [l.split[0..-2].join ,l.split[-1].to_i/1024]}
- #summing rows with same progname
- sum=Hash.new(0)
- table.each {|i| sum[i[0]]+=i[1]}
- # sort decrasing on second field (memory use)
- table=sum.to_a.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+") "
- }.chop
Advertisement
Add Comment
Please, Sign In to add comment