Skip to content

Instantly share code, notes, and snippets.

@tobstarr
Created October 25, 2012 12:12
Show Gist options
  • Save tobstarr/3952247 to your computer and use it in GitHub Desktop.
Save tobstarr/3952247 to your computer and use it in GitHub Desktop.
class SystemProcess
def initialize(pid)
@pid = pid
end
def started_at
self.class.time_of_boot + started_seconds_after_boot
end
class << self
def uptime
`cat /proc/uptime`.split(" ").first.to_f
end
def time_of_boot
Time.now - uptime
end
end
private
def started_seconds_after_boot
`cat /proc/#{@pid}/stat`.split(" ")[21].to_i / 100.0
end
end
puts Time.now
sleep 10
puts SystemProcess.new(Process.pid).started_at
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment