process-metrics 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 43c70d72392b299b8219b1bb1d5762de8d4ee116568ebd4ada928ba946d3ae96
4
- data.tar.gz: d0c5a4ab4a3fd2935e95667fff758c20c87f14165776dec5b908f544cc24a590
3
+ metadata.gz: b288419449c98ce2b53cc2ecb8d3d2660a473c17677b66e6f18015b803db1482
4
+ data.tar.gz: 67b4d639f7744814e47e61aac54ef7c588557a94ca8454926594d742f9cf88ce
5
5
  SHA512:
6
- metadata.gz: 91961040cacd7a310a28ab42b76ff4f73386bdbd77a36138b7e5e4a3704fed2e6184ad493629ad501e45473c0013bbe675a4c159d74efc723a1cdb138b1a1df7
7
- data.tar.gz: 9de09390fbc96a7dc208914fd18aeed8d0380f49fb3bc4ab8bf33ec1e15dba671d48921eb71460a33aba779d409cd4180c7f811f42ff736ddd4bf48d2971958e
6
+ metadata.gz: 0a1686b0609d8009a2d5a26b659876c29c5378d89b35b39777b5d55d53413b2a10558470075ce0303959f77213ceef101cad19547dc95743440d0243af2746e1
7
+ data.tar.gz: 13a3e9bbc06eb5412a6b37c499f531eebf58317c1944d0e679dd68d8b87abc4450e62b7166c435334745555d26bb873b9ddc47d65324bdf17832b27865f60a2c
checksums.yaml.gz.sig CHANGED
Binary file
@@ -137,25 +137,40 @@ module Process
137
137
  #
138
138
  # @parameter pid [Integer] The process ID to capture.
139
139
  # @parameter ppid [Integer] The parent process ID to capture.
140
- def self.capture(pid: nil, ppid: nil, ps: PS, memory: Memory.supported?)
141
- input, output = IO.pipe
140
+ def self.capture(pid: nil, ppid: nil, memory: Memory.supported?)
141
+ ps_pid = nil
142
142
 
143
- arguments = [ps]
144
-
145
- if pid && ppid.nil?
146
- arguments.push("-p", Array(pid).join(","))
147
- else
148
- arguments.push("ax")
143
+ # Extract the information from the `ps` command:
144
+ header, *lines = IO.pipe do |input, output|
145
+ arguments = [PS]
146
+
147
+ if pid && ppid.nil?
148
+ arguments.push("-p", Array(pid).join(","))
149
+ else
150
+ arguments.push("ax")
151
+ end
152
+
153
+ arguments.push("-o", FIELDS.keys.join(","))
154
+
155
+ ps_pid = Process.spawn(*arguments, out: output)
156
+ output.close
157
+
158
+ input.readlines.map(&:strip)
159
+ ensure
160
+ input.close
161
+
162
+ if ps_pid
163
+ begin
164
+ # Make sure to kill the ps process if it's still running:
165
+ Process.kill(:KILL, ps_pid)
166
+ # Reap the process:
167
+ Process.wait(ps_pid)
168
+ rescue => error
169
+ warn "Failed to cleanup ps process #{ps_pid}:\n#{error.full_message}"
170
+ end
171
+ end
149
172
  end
150
173
 
151
- arguments.push("-o", FIELDS.keys.join(","))
152
-
153
- ps_pid = Process.spawn(*arguments, out: output, pgroup: true)
154
-
155
- output.close
156
-
157
- header, *lines = input.readlines.map(&:strip)
158
-
159
174
  processes = {}
160
175
 
161
176
  lines.map do |line|
@@ -187,8 +202,6 @@ module Process
187
202
  end
188
203
 
189
204
  return processes
190
- ensure
191
- Process.wait(ps_pid) if ps_pid
192
205
  end
193
206
  end
194
207
  end
@@ -71,8 +71,8 @@ module Process
71
71
 
72
72
  return usage
73
73
  end
74
- rescue Errno::ENOENT, Errno::ESRCH
75
- # Process doesn't exist.
74
+ rescue Errno::ENOENT, Errno::ESRCH, Errno::EACCES
75
+ # Process doesn't exist or we can't access it.
76
76
  return nil
77
77
  end
78
78
  elsif File.readable?("/proc/self/smaps")
@@ -105,8 +105,8 @@ module Process
105
105
 
106
106
  return usage
107
107
  end
108
- rescue Errno::ENOENT, Errno::ESRCH
109
- # Process doesn't exist.
108
+ rescue Errno::ENOENT, Errno::ESRCH, Errno::EACCES
109
+ # Process doesn't exist or we can't access it.
110
110
  return nil
111
111
  end
112
112
  else
@@ -7,6 +7,6 @@
7
7
  module Process
8
8
  # @namespace
9
9
  module Metrics
10
- VERSION = "0.7.0"
10
+ VERSION = "0.8.0"
11
11
  end
12
12
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: process-metrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
metadata.gz.sig CHANGED
Binary file