Skip to content

Commit bfc6e31

Browse files
committed
JT: Send SIGKILL after 1 second if the process did not terminate after SIGTERM
* Share the logic to send signals.
1 parent 581e3a5 commit bfc6e31

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

tool/jt.rb

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,7 @@
9898
[:SIGINT, :SIGTERM].each do |signal|
9999
trap(signal) do
100100
SUBPROCESSES.each do |pid|
101-
puts "\nSending #{signal} to process #{pid}"
102-
begin
103-
Process.kill(signal, pid)
104-
rescue Errno::ESRCH
105-
# Already killed
106-
end
101+
Utilities.send_signal(signal, pid)
107102
end
108103
# Keep running jt which will wait for the subprocesses termination
109104
end
@@ -137,6 +132,17 @@ def jvmci_update_and_version
137132
[update, jvmci]
138133
end
139134

135+
def send_signal(signal, pid)
136+
STDERR.puts "\nSending #{signal} to process #{pid}"
137+
begin
138+
Process.kill(signal, pid)
139+
rescue Errno::ESRCH
140+
# Already killed
141+
nil
142+
end
143+
end
144+
module_function :send_signal
145+
140146
def which(binary)
141147
ENV["PATH"].split(File::PATH_SEPARATOR).each do |dir|
142148
path = "#{dir}/#{binary}"
@@ -259,7 +265,10 @@ def raw_sh_with_timeout(timeout, pid)
259265
yield
260266
end
261267
rescue Timeout::Error
262-
Process.kill('TERM', pid)
268+
if send_signal(:SIGTERM, pid)
269+
sleep 1
270+
send_signal(:SIGKILL, pid)
271+
end
263272
yield # Wait and read the pipe if capture: true
264273
:timeout
265274
end

0 commit comments

Comments
 (0)