Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/childprocess/process_spawn_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def exited?
return true if @exit_code

assert_started
pid, status = ::Process.waitpid2(@pid, ::Process::WNOHANG | ::Process::WUNTRACED)
pid, status = ::Process.waitpid2(@pid, ::Process::WNOHANG)
pid = nil if pid == 0 # may happen on jruby

log(:pid => pid, :status => status)
Expand Down
15 changes: 15 additions & 0 deletions spec/unix_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@
describe ChildProcess::Unix::Process do
it_behaves_like "a platform that provides the child's pid"

it "does not treat a stopped child as exited" do
process = sleeping_ruby.start
Process.kill("STOP", process.pid)

wait_until do
IO.popen(["ps", "-o", "state=", "-p", process.pid.to_s], &:read).strip.start_with?("T")
end
expect(process).not_to be_exited

Process.kill("CONT", process.pid)
process.stop
ensure
Process.kill("CONT", process.pid) if process&.alive?
end

it "handles ECHILD race condition where process dies between timeout and KILL" do
process = sleeping_ruby

Expand Down