Method: LinuxStat::ProcessInfo.threads
- Defined in:
- lib/linux_stat/process_info.rb
.threads(pid = $$) ⇒ Object
threads(pid = $$)
Where pid is the process ID.
By default it is the id of the current process ($$)
It retuns the threads for the current process in Integer.
For example:
LinuxStat::ProcessInfo.threads
=> 2
But if the info isn’t available, it will return nil.
This method is way more efficient than running LinuxStat::ProcessInfo.cpu_stat()
462 463 464 465 466 467 468 |
# File 'lib/linux_stat/process_info.rb', line 462 def threads(pid = $$) file = "/proc/#{pid}/stat".freeze return nil unless File.readable?(file) data = IO.read(file).split(/(\(.*\))/)[-1] &.split &.at(17) data ? data.to_i : nil end |