Module: LinuxStat::Process
- Defined in:
- lib/linux_stat/process.rb
Overview
Shows various information about a process that is either running, sleeping, idle or a zombie.
Class Method Summary collapse
-
.cmdlines ⇒ Object
Returns all the id of processes mapped with their cmdline info as a Hash.
-
.count ⇒ Object
Counts and returns the total number of process running on the system.
-
.idle ⇒ Object
Returns all the id of processes that are idle.
-
.last_pid ⇒ Object
Returns the last_pid of the system.
-
.list ⇒ Object
Returns the list of processes from /proc/.
-
.names ⇒ Object
Returns all the id of processes mapped with their executable names (comm) as a Hash.
-
.running ⇒ Object
Returns all the id of processes that are running.
-
.sleeping ⇒ Object
Returns all the id of processes that are sleeping.
-
.stopped ⇒ Object
Returns all the id of processes that are stopped.
-
.types ⇒ Object
Returns all the id of processes mapped with their status as a Hash.
-
.zombie ⇒ Object
Returns all the id of processes that are zombies.
Class Method Details
.cmdlines ⇒ Object
Returns all the id of processes mapped with their cmdline info as a Hash. The cmdlines aren’t usually truncated like names, but they can contain arguments with the command.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/linux_stat/process.rb', line 47 def cmdlines h, i = {}, -1 l = LinuxStat::ProcFS.list_process count = l.length while(i += 1) < count x = l[i] begin cmdlines = IO.read("/proc/#{x}/cmdline").strip cmdlines.gsub!(?\u0000.freeze, ?\s.freeze) h.store(x, cmdlines) rescue StandardError end end h end |
.count ⇒ Object
Counts and returns the total number of process running on the system.
The return type is Integer.
19 20 21 |
# File 'lib/linux_stat/process.rb', line 19 def count LinuxStat::ProcFS.list_process.length end |
.idle ⇒ Object
Returns all the id of processes that are idle. The return type is an Array of Integers.
110 111 112 113 114 |
# File 'lib/linux_stat/process.rb', line 110 def idle LinuxStat::ProcFS.list_process.select { |x| LinuxStat::ProcFS.ps_state(x) == ?I.freeze } end |
.last_pid ⇒ Object
Returns the last_pid of the system. It directly calls LS::ProcFS.last_pid
The return value is Integer, but if the status isn’t available, it will return nil
150 151 152 |
# File 'lib/linux_stat/process.rb', line 150 def last_pid LinuxStat::ProcFS.last_pid end |
.list ⇒ Object
Returns the list of processes from /proc/. The output doesn’t guarantee a sorted list, in fact it’s shuffled most of the time.
The return type is an Array of Integers.
11 12 13 |
# File 'lib/linux_stat/process.rb', line 11 def list LinuxStat::ProcFS.list_process end |
.names ⇒ Object
Returns all the id of processes mapped with their executable names (comm) as a Hash. The names can be truncated to TASK_COMM_LEN or (16 - 1 = 15) places.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/linux_stat/process.rb', line 26 def names h, i = {}, -1 l = LinuxStat::ProcFS.list_process count = l.length while(i += 1) < count x = l[i] begin h.store(x, IO.read("/proc/#{x}/comm").strip) rescue StandardError end end h end |
.running ⇒ Object
Returns all the id of processes that are running. The return type is an Array of Integers.
128 129 130 131 132 |
# File 'lib/linux_stat/process.rb', line 128 def running LinuxStat::ProcFS.list_process.select { |x| LinuxStat::ProcFS.ps_state(x) == ?R.freeze } end |
.sleeping ⇒ Object
Returns all the id of processes that are sleeping. The return type is an Array of Integers.
101 102 103 104 105 |
# File 'lib/linux_stat/process.rb', line 101 def sleeping LinuxStat::ProcFS.list_process.select { |x| LinuxStat::ProcFS.ps_state(x) == ?S.freeze } end |
.stopped ⇒ Object
Returns all the id of processes that are stopped. The return type is an Array of Integers.
137 138 139 140 141 142 |
# File 'lib/linux_stat/process.rb', line 137 def stopped LinuxStat::ProcFS.list_process.select { |x| v = LinuxStat::ProcFS.ps_state(x) v == ?T.freeze || v == ?t.freeze } end |
.types ⇒ Object
Returns all the id of processes mapped with their status as a Hash.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/linux_stat/process.rb', line 68 def types h, i = {}, -1 l = LinuxStat::ProcFS.list_process count = l.length while(i += 1) < count x = l[i] begin h.store(x, case LinuxStat::ProcFS.ps_state(x) when ?S.freeze then :sleeping when ?I.freeze then :idle when ?Z.freeze then :zombie when ?R.freeze then :running when ?T.freeze then :stopped when ?X.freeze then :dead when ?D.freeze then :sleeping when ?t.freeze then :stopped else :unknown end ) rescue StandardError end end h end |