Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lukehorvat opened this Issue Jul 8, 2015 · 7 comments

Comments

Projects
None yet
4 participants
@lukehorvat
Copy link

commented Jul 8, 2015

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?

@enebo enebo added this to the JRuby 9.0.0.0 milestone Jul 8, 2015

@enebo

This comment has been minimized.

Copy link
Member

commented Jul 8, 2015

Tried this on 9k also and it is a little better:

false
false

but still broken. So both branches have issue(s).

@headius

This comment has been minimized.

Copy link
Member

commented Jul 9, 2015

I would guess that WNOHANG is not doing anything. Investigating.

@headius

This comment has been minimized.

Copy link
Member

commented Jul 9, 2015

Nevermind, WNOHANG seems ok. We just weren't returning nil for a zero result from waitpid. Fixing.

@headius headius closed this in e4b3f8b Jul 9, 2015

headius added a commit that referenced this issue Jul 9, 2015

@headius headius modified the milestones: JRuby 1.7.22, JRuby 9.0.0.0 Jul 9, 2015

@headius

This comment has been minimized.

Copy link
Member

commented Jul 9, 2015

Fixed for 9k.rc2 and 1.7.22.

@lukehorvat

This comment has been minimized.

Copy link
Author

commented Jul 10, 2015

@headius Thanks!

eregon added a commit that referenced this issue Jul 15, 2015

Squashed 'spec/ruby/' changes from e56bc0d..e3e7dd7
e3e7dd7 Improve Thread#wakeup spec
99bb111 Remove outdated spec
c131731 Add missing stdlib require
69e04f0 Add spec for waitpid(... WNOHANG) returning nil. #3117.
48f098d Be more precise in Module#prepend example
0f05e29 Add spec for Module#prepend
14f4954 Add a spec to ensure Module#prepended is called by #prepend
7030731 Add missing cases to BigDecimal#div specs
5db8638 Make the path for a UNIX domain socket shorter as it is quite limited on Linux
3874369 Add proper before/after blocks for a File.socket? spec
f0b29f8 Clarify where class variables get defined
1b3b3ce Add spec for Binding#local_variable_set.

git-subtree-dir: spec/ruby
git-subtree-split: e3e7dd78ef23b08af2447701ea4f6e51c4b104a1

kares added a commit that referenced this issue Jul 17, 2015

Merge branch 'jruby-1_7' into master
* jruby-1_7: (36 commits)
  no need for "" + ...
  keep the test Java 6 compilable + more asserts
  method cache hash calc needs to acount for Proc
  support for matching proc-to-iface methods by arity
  improve resolving functional-interfaces
  avoid reflection in getFunctionalInterface
  some Java.getFunctionalInterfaceMethod asserts
  introduce a getFunctionalInterfaceMethod helper
  generix-ize some of JavaUtil's static helpers
  Make sure windows files generate signatures as part of post_process_artifacts
  Doh...how did this not get added
  Fixes #3135. Provide sha256 sums
  yet another multiple args proc-to-iface spec
  less deprecation warnings from implementation_spec
  clean + avoid deprecation warn in executor_spec
  less rspec deprecation warnings from ant spec
  avoid File#listFiles in spec since it's ambiguous
  spec for regression in proc to iface optimization
  Fix references to old mailing lists.
  Return nil when waitpid returns 0. Fixes #3117.
  ...

Conflicts:
	VERSION
	antlib/extra.xml
	core/pom.xml
	core/src/main/java/org/jruby/RubyProcess.java
	core/src/main/java/org/jruby/embed/util/SystemPropertyCatcher.java
	core/src/test/java/org/jruby/embed/ScriptingContainerTest.java
	docs/man/pom.xml
	docs/pom.xml
	ext/pom.xml
	ext/readline/pom.xml
	ext/ripper/pom.xml
	lib/pom.xml
	maven/jruby-complete/pom.xml
	maven/jruby-dist/pom.xml
	maven/jruby-dist/src/main/assembly/jruby.xml
	maven/jruby-jars/pom.xml
	maven/jruby-noasm/pom.xml
	maven/jruby-rake-plugin/pom.xml
	maven/jruby-stdlib/pom.xml
	maven/jruby/pom.xml
	maven/pom.xml
	pom.xml
	test/pom.xml
	test/test_backquote.rb
	test/test_kernel.rb
@Freaky

This comment has been minimized.

Copy link
Contributor

commented Aug 7, 2015

I think you missed fixing Process.waitpid2:

Process.waitpid2(Process.spawn("/bin/sleep", "5"), Process::WNOHANG)
=> [0, #<Process::Status: pid 0 signal 36>] 

jruby 9.0.1.0-SNAPSHOT (2.2.2) 2015-08-01 6a9fcf8 OpenJDK 64-Bit Server VM 25.51-b03 on 1.8.0_51-b16 +jit [FreeBSD-amd64]

headius added a commit that referenced this issue Aug 7, 2015

headius added a commit that referenced this issue Aug 7, 2015

Fix waitpid2 to return proper result when ret = 0.
Missed fix for #3117.

Conflicts:
	core/src/main/java/org/jruby/RubyProcess.java
@headius

This comment has been minimized.

Copy link
Member

commented Aug 7, 2015

@Freaky Good catch! Fixed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.