Skip to content

Commit bca8a29

Browse files
committed
Kill ps before waiting to avoid hanging.
1 parent 613a0de commit bca8a29

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

lib/process/metrics/general.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def self.capture(pid: nil, ppid: nil, ps: PS, memory: Memory.supported?)
150150

151151
arguments.push("-o", FIELDS.keys.join(","))
152152

153-
ps_pid = Process.spawn(*arguments, out: output, pgroup: true)
153+
ps_pid = Process.spawn(*arguments, out: output)
154154

155155
output.close
156156

@@ -188,7 +188,16 @@ def self.capture(pid: nil, ppid: nil, ps: PS, memory: Memory.supported?)
188188

189189
return processes
190190
ensure
191-
Process.wait(ps_pid) if ps_pid
191+
if ps_pid
192+
begin
193+
# Make sure to kill the ps process if it's still running:
194+
Process.kill(:KILL, ps_pid)
195+
# Reap the process:
196+
Process.wait(ps_pid)
197+
rescue => error
198+
warn "Failed to cleanup ps process #{ps_pid}:\n#{error.full_message}"
199+
end
200+
end
192201
end
193202
end
194203
end

0 commit comments

Comments
 (0)