Skip to content

Instantly share code, notes, and snippets.

@remogatto
Created August 9, 2009 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save remogatto/164777 to your computer and use it in GitHub Desktop.
Save remogatto/164777 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'ffi'
class Info
extend FFI::Library
BOOT_TIME = 2
attach_function :setutxent, [], :void
attach_function :getutxent, [], :pointer
attach_function :endutxent, [], :void
class Timeval < FFI::Struct
layout( :tv_sec, :long,
:tv_usec, :long )
end
class ExitStatus < FFI::Struct
layout( :e_termination, :short,
:e_exit, :short )
end
class Utmpx < FFI::Struct
layout( :ut_type, :short,
:ut_pid, :pid_t,
:ut_line, [:char, 32],
:ut_id, :char,
:ut_user, [:char, 32],
:ut_host, [:char, 256],
:ut_exit, ExitStatus,
:ut_session, :long,
:ut_tv, Timeval )
end
def self.getstuff
begin
setutxent
ent = Utmpx.new(getutxent())
time = Time.at(ent[:ut_tv][:tv_sec], ent[:ut_tv][:tv_usec]) if ent[:ut_type] == BOOT_TIME
ensure
endutxent
end
end
end
puts "Boot time: #{Info.getstuff}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment