Skip to content

Unexpected behaviour of Process.waitpid...? #3117

@lukehorvat

Description

@lukehorvat

test.rb:

pid = Process.spawn("sleep 3")
puts Process.waitpid(pid, Process::WNOHANG).nil?
sleep 6
puts Process.waitpid(pid, Process::WNOHANG).nil?

Executing the script above with Ruby v2.2.2 produces the following output:

true
false

And executing it with JRuby v1.7.20 produces this:

false
Errno::ECHILD: No child processes - No child processes
  waitpid at org/jruby/RubyProcess.java:536
  waitpid at org/jruby/RubyProcess.java:521
   (root) at test.rb:4

It seems Process.waitpid returns zero instead of nil while the child process hasn't exited. Is this different behaviour known/expected?

If it is, what is the best way to check that a child process is still running and has not exited yet? Simply Process.waitpid(pid, Process::WNOHANG) == 0?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions