From: Gregory Brown Date: 2005-11-17T14:00:59+09:00 Subject: Re: Improving code... On 11/16/05, Joe Van Dyk wrote: > # See 'man proc' for details. > def get_process_stats > proc_stats = File.read("/proc/#{ @pid }/stat") > > # EEWWWW -- gets the stuff from /proc//stat and puts it into vars > pid, comm, state, ppid, pgrp, session, tty_nr, tpgid, flags, > minflt, cminflt, majflt, cmajflt, utime, stime, cutime, > cstime, priority, nice, who_cares, itrealvade, > starttime, vsize, rss, rlim, startcode, endcode, startstack, > kstkesp, kstkeip, signal, blocked, sigignore, sigcatch, > wchan, nswap, cnswap, exit_signal, processor = > proc_stats.scanf("%d %s %c %d %d %d %d %d %d %d \ > %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d \ > %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d") proc_stats = File.read("/proc/#{ @pid }/stat").split(" ") you might need to change your split to match the appropriate pattern, matching a space above. This makes proc_stats an array > # Just put the ones I need into the hash > stats = {} > stats[:system_cpu_time] = stime > stats[:user_cpu_time] = utime > stats[:processor] = processor > stats > end > end stats = { :system_cpu_time => proc_stats[14], :user_cpu_time => proc_stats[13], :processor => proc_stats.last } the indicies might not be correct above, but hopefully the idea works ;)