-
-
Save tobstarr/3952247 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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