1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

process.c: add Process.last_status

* process.c (proc_s_last_status): add Process.last_status
  [ruby-core:83514] [Feature #14043]

* test/ruby/test_process.rb (test_last_status): add a test case for
  Process.last_status.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61143 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mrkn 2017-12-12 09:00:17 +00:00
parent 79c2e6eccf
commit 8624cec9d3
2 changed files with 27 additions and 0 deletions

View file

@ -472,6 +472,27 @@ rb_last_status_get(void)
return GET_THREAD()->last_status;
}
/*
* call-seq:
* Process.last_status -> Process::Status
*
* Return the status of the last executed child process in the
* current thread.
*
* Process.wait Process.spawn("ruby", "-e", "exit 13")
* Process.last_status #=> #<Process::Status: pid 4825 exit 13>
*
* If no child process has never been executed in the current
* thread, this returns +nil+.
*
* Process.last_status #=> nil
*/
static VALUE
proc_s_last_status(VALUE mod)
{
return rb_last_status_get();
}
void
rb_last_status_set(int status, rb_pid_t pid)
{
@ -7600,6 +7621,7 @@ InitVM_process(void)
rb_define_singleton_method(rb_mProcess, "exit!", rb_f_exit_bang, -1);
rb_define_singleton_method(rb_mProcess, "exit", rb_f_exit, -1);
rb_define_singleton_method(rb_mProcess, "abort", rb_f_abort, -1);
rb_define_singleton_method(rb_mProcess, "last_status", proc_s_last_status, 0);
rb_define_module_function(rb_mProcess, "kill", rb_f_kill, -1); /* in signal.c */
rb_define_module_function(rb_mProcess, "wait", proc_wait, -1);

View file

@ -2352,4 +2352,9 @@ EOS
end
end
end
def test_last_status
Process.wait spawn(RUBY, "-e", "exit 13")
assert_same(Process.last_status, $?)
end
end