fork with exit [some integer] seems to not change exitstatus in Process.wait2, ruby 2.2.4

Kelly Felkins <[email protected]>
Newsgroups gmane.comp.lang.ruby.general
Message-ID <CAGHx4SjDk=5o9LRxOGqQe9e+0YJJSaakZbiQ8xxROfOBrTwWTg@mail.gmail.com>
Happy New Year ruby-talk.

I'm attempting to retrieve the exit status of child processes. So far, no
matter how the child process exists, wait2 status only has a 1 for
exitstatus.

I'm also seeing "unexpected throw" messages. Perhaps I'm doing something
that is causing the unexpected throw, which is causing the exit status to
be 1.

ruby:
    interpreter:  "ruby"
    version:      "2.4.4p296"
    date:         "2018-03-28"
    platform:     "x86_64-darwin17"
    patchlevel:   "2018-03-28 revision 63013"
    full_version: "ruby 2.4.4p296 (2018-03-28 revision 63013)
[x86_64-darwin17]"

OSX: 10.13.6 (17G4015)

sample code:

pid = fork do
  sleep 2
  exit 555
end

returned_pid, status = Process.wait2

puts "pid: #{pid}, returned_pid: #{returned_pid}, status:
#{status.inspect}, exitstatus: #{status.exitstatus}"

pid = fork do
  sleep 2
  exit 0
end

returned_pid, status = Process.wait2

puts "pid: #{pid}, returned_pid: #{returned_pid}, status:
#{status.inspect}, exitstatus: #{status.exitstatus}"


Session:

2.4.4 :001 > pid = fork do

2.4.4 :002 >       sleep 2
2.4.4 :003?>     exit 555
2.4.4 :004?>   end
 => 91187
2.4.4 :005 >
2.4.4 :006 >   returned_pid, status = Process.wait2
(irb):1:in `fork': unexpected throw
 => [91187, #<Process::Status: pid 91187 exit 1>]
2.4.4 :007 >
2.4.4 :008 >   puts "pid: #{pid}, returned_pid: #{returned_pid},
status: #{status.inspect}, exitstatus: #{status.exitstatus}"
pid: 91187, returned_pid: 91187, status: #<Process::Status: pid 91187
exit 1>, exitstatus: 1
 => nil
2.4.4 :009 >
2.4.4 :010 >   pid = fork do
2.4.4 :011 >       sleep 2
2.4.4 :012?>     exit 0
2.4.4 :013?>   end
 => 91188
2.4.4 :014 >
2.4.4 :015 >   returned_pid, status = Process.wait2
(irb):10:in `fork': unexpected throw
 => [91188, #<Process::Status: pid 91188 exit 1>]
2.4.4 :016 >
2.4.4 :017 >   puts "pid: #{pid}, returned_pid: #{returned_pid},
status: #{status.inspect}, exitstatus: #{status.exitstatus}"
pid: 91188, returned_pid: 91188, status: #<Process::Status: pid 91188
exit 1>, exitstatus: 1
 => nil





-- 
Join the conversation in your neighborhood.
Register for Oakland's homegrown neighbor network, JustMyNeighbors.com

https://www.justmyneighbors.com/register


Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.