Class: GetProcessStartTime

Inherits:
Object
  • Object
show all
Defined in:
lib/get_process_start_time.rb,
lib/get_process_start_time/cli.rb,
lib/get_process_start_time/version.rb,
ext/get_process_start_time/get_process_start_time.c

Defined Under Namespace

Classes: CLI

Constant Summary collapse

VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.clock_tickObject

Etc.sysconf(Etc::SC_CLK_TCK)



9
10
11
12
13
14
# File 'ext/get_process_start_time/get_process_start_time.c', line 9

static VALUE
rb_clock_tick(VALUE self)
{
    long hertz = (double)sysconf(_SC_CLK_TCK);
    return LONG2NUM(hertz);
}

.convert_into_start_time(start_time_jiffies) ⇒ Time

Returns:

  • (Time)


20
21
22
# File 'lib/get_process_start_time.rb', line 20

def self.convert_into_start_time(start_time_jiffies)
  time_of_boot + (start_time_jiffies / clock_tick)
end

.start_time(pid) ⇒ Time

Returns:

  • (Time)


7
8
9
10
# File 'lib/get_process_start_time.rb', line 7

def self.start_time(pid)
  stats = File.read("/proc/#{pid}/stat").chomp.split(/\s+/)
  convert_into_start_time(stats[21].to_f)
end

.time_of_bootTime

Returns:

  • (Time)


13
14
15
16
17
# File 'lib/get_process_start_time.rb', line 13

def self.time_of_boot
  return @time_of_boot if @time_of_boot
  seconds_since_boot = File.read('/proc/uptime').split(/\s+/).first.to_f
  @time_of_boot = Time.now - seconds_since_boot
end