Class: Process::Status
Overview
A Status contains information about a system process.
Thread-local variable $? is initially nil. Some methods assign to it a Status object that represents a system process (either running or terminated):
`ruby -e "exit 99"`
stat = $? # => #<Process::Status: pid 1262862 exit 99>
stat.class # => Process::Status
stat.to_i # => 25344
stat.stopped? # => false
stat.exited? # => true
stat.exitstatus # => 99
Instance Attribute Summary
-
#coredump? ⇒ Boolean
readonly
Returns
trueif the process generated a coredump when it terminated,falseif not. -
#exited? ⇒ Boolean
readonly
Returns
trueif the process exited normally (for example using anexit()call or finishing the program),falseif not. -
#signaled? ⇒ Boolean
readonly
Returns
trueif the process terminated because of an uncaught signal,falseotherwise. - #stopped? ⇒ Boolean readonly
-
#success? ⇒ Boolean
readonly
Returns:
Instance Method Summary
-
#==(other) ⇒ Boolean
Returns whether the value of #to_i ==
other: -
#exitstatus ⇒ Integer?
Returns the least significant eight bits of the return code of the process if it has exited;
nilotherwise: -
#inspect ⇒ String
Returns a string representation of
self: -
#pid ⇒ Integer
Returns the process ID of the process:
-
#stopsig ⇒ Integer?
Returns the number of the signal that caused the process to stop, or
nilif the process is not stopped. -
#termsig ⇒ Integer?
Returns the number of the signal that caused the process to terminate or
nilif the process was not terminated by an uncaught signal. -
#to_i ⇒ Integer
Returns the system-dependent integer status of
self: -
#to_s ⇒ String
Returns a string representation of
self:
Instance Attribute Details
#coredump? ⇒ Boolean (readonly)
Returns true if the process generated a coredump when it terminated, false if not.
Not available on all platforms.
# File 'process.c', line 1024
static VALUE
pst_wcoredump(VALUE st)
{
#ifdef WCOREDUMP
int status = PST2INT(st);
return RBOOL(WCOREDUMP(status));
#else
return Qfalse;
#endif
}
#exited? ⇒ Boolean (readonly)
Returns true if the process exited normally (for example using an exit() call or finishing the program), false if not.
# File 'process.c', line 958
static VALUE
pst_wifexited(VALUE st)
{
int status = PST2INT(st);
return RBOOL(WIFEXITED(status));
}
#signaled? ⇒ Boolean (readonly)
Returns true if the process terminated because of an uncaught signal, false otherwise.
# File 'process.c', line 921
static VALUE
pst_wifsignaled(VALUE st)
{
int status = PST2INT(st);
return RBOOL(WIFSIGNALED(status));
}
#stopped? ⇒ Boolean (readonly)
Returns true if this process is stopped, and if the corresponding Process#wait call had the WUNTRACED flag set, false otherwise.
# File 'process.c', line 885
static VALUE
pst_wifstopped(VALUE st)
{
int status = PST2INT(st);
return RBOOL(WIFSTOPPED(status));
}
#success? ⇒ Boolean (readonly)
Returns:
-
trueif the process has completed successfully and exited. -
falseif the process has completed unsuccessfully and exited. -
nilif the process has not exited.
# File 'process.c', line 1003
static VALUE
pst_success_p(VALUE st)
{
int status = PST2INT(st);
if (!WIFEXITED(status))
return Qnil;
return RBOOL(WEXITSTATUS(status) == EXIT_SUCCESS);
}
Instance Method Details
#==(other) ⇒ Boolean
# File 'process.c', line 868
static VALUE
pst_equal(VALUE st1, VALUE st2)
{
if (st1 == st2) return Qtrue;
return rb_equal(pst_to_i(st1), st2);
}
#exitstatus ⇒ Integer?
Returns the least significant eight bits of the return code of the process if it has exited; nil otherwise:
`exit 99`
$?.exitstatus # => 99
# File 'process.c', line 980
static VALUE
pst_wexitstatus(VALUE st)
{
int status = PST2INT(st);
if (WIFEXITED(status))
return INT2NUM(WEXITSTATUS(status));
return Qnil;
}
#inspect ⇒ String
Returns a string representation of self:
system("false")
$?.inspect # => "#<Process::Status: pid 1303494 exit 1>"
# File 'process.c', line 835
static VALUE
pst_inspect(VALUE st)
{
rb_pid_t pid;
int status;
VALUE str;
pid = pst_pid(st);
if (!pid) {
return rb_sprintf("#<%s: uninitialized>", rb_class2name(CLASS_OF(st)));
}
status = PST2INT(st);
str = rb_sprintf("#<%s: ", rb_class2name(CLASS_OF(st)));
pst_message(str, pid, status);
rb_str_cat2(str, ">");
return str;
}
#pid ⇒ Integer
Returns the process ID of the process:
system("false")
$?.pid # => 1247002
# File 'process.c', line 745
static VALUE
pst_pid_m(VALUE self)
{
rb_pid_t pid = pst_pid(self);
return PIDT2NUM(pid);
}
#stopsig ⇒ Integer?
Returns the number of the signal that caused the process to stop, or nil if the process is not stopped.
# File 'process.c', line 902
static VALUE
pst_wstopsig(VALUE st)
{
int status = PST2INT(st);
if (WIFSTOPPED(status))
return INT2NUM(WSTOPSIG(status));
return Qnil;
}
#termsig ⇒ Integer?
Returns the number of the signal that caused the process to terminate or nil if the process was not terminated by an uncaught signal.
# File 'process.c', line 938
static VALUE
pst_wtermsig(VALUE st)
{
int status = PST2INT(st);
if (WIFSIGNALED(status))
return INT2NUM(WTERMSIG(status));
return Qnil;
}
#to_i ⇒ Integer
Returns the system-dependent integer status of self:
`cat /nop`
$?.to_i # => 256
# File 'process.c', line 725
static VALUE
pst_to_i(VALUE self)
{
int status = pst_status(self);
return RB_INT2NUM(status);
}
#to_s ⇒ String
Returns a string representation of self:
`cat /nop`
$?.to_s # => "pid 1262141 exit 1"
# File 'process.c', line 808
static VALUE
pst_to_s(VALUE st)
{
rb_pid_t pid;
int status;
VALUE str;
pid = pst_pid(st);
status = PST2INT(st);
str = rb_str_buf_new(0);
pst_message(str, pid, status);
return str;
}