Method: LinuxStat::ProcessInfo.running_time

Defined in:
lib/linux_stat/process_info.rb

.running_time(pid = $$) ⇒ Object

running_time(pid = $$)

Returns the time (in seconds, as Float) the process is running for.

For example:

LinuxStat::ProcessInfo.running_time 14183

=> 1947.61

It always rounds the float number upto 2 decimal places

If the info isn’t available or the argument passed doesn’t exist as a process ID, it will return nil.



540
541
542
543
544
545
# File 'lib/linux_stat/process_info.rb', line 540

def running_time(pid = $$)
	uptime = LS::ProcFS.uptime_f
	stat = LinuxStat::ProcFS.ps_stat(pid)[18]
	return nil unless uptime && stat
	uptime.-(stat.to_f / get_ticks).round(2)
end