Module: Howlong
- Defined in:
- lib/howlong.rb,
lib/howlong/version.rb
Constant Summary collapse
- VERSION =
"0.0.1"
Class Method Summary collapse
Class Method Details
.find_processes(search) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/howlong.rb', line 5 def self.find_processes(search) processes = `ps -eo lstart,args | grep #{search}`.split(/\n/) names = [] processes.each do |p| process = p.match(/\S+#{search}/) # Make sure the first executable contains the search string, so we # won't catch processes such as grep `parameter` or this script: if process time = elapsed_time(p) names << [process[0], time] end end names end |
.run(process) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/howlong.rb', line 34 def self.run(process) processes = find_processes(process) processes.each do |p| show(p[0], p[1]) end end |
.show(process, delayed) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/howlong.rb', line 20 def self.show(process, delayed) unless delayed == nil print = "Process #{process} has been active for " if delayed[:days] > 0 print += "#{delayed[:days]} days, #{(delayed[:seconds].to_int / 86_400) % 24} hours, #{delayed[:minutes] % 60} minutes " elsif delayed[:hours] > 0 print += "#{delayed[:hours]} hours, #{delayed[:minutes] % 60} minutes " else print += "#{delayed[:minutes]} minutes " end puts print + "and #{delayed[:seconds] % delayed[:minutes]} seconds" end end |