Method: LinuxStat::ProcessInfo.state

Defined in:
lib/linux_stat/process_info.rb

.state(pid = $$) ⇒ Object

state(pid = $$)

Returns the state of the process as a frozen String

  • A process could have multiple states:

  1. S => Sleeping

  2. R => Running

  3. I => Idle

  4. Z => Zombie

It returns any one of them.

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



592
593
594
595
596
# File 'lib/linux_stat/process_info.rb', line 592

def state(pid = $$)
	file = "/proc/#{pid}/stat".freeze
	return ''.freeze unless File.readable?(file)
	IO.foreach(file, ' '.freeze).first(3)[-1].tap(&:rstrip!).freeze
end