Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
class method
PTY.check
(::Integer pid, ?::boolish raise) -> ::Process::Status?
PTY.check(pid, raise = false) => Process::Status or nil
PTY.check(pid, true) => nil or raises PTY::ChildExited
ext/pty/pty.c
View on GitHub ↗
static VALUE
pty_check(int argc, VALUE *argv, VALUE self)
{
VALUE pid, exc;
rb_pid_t cpid;
int status;
const int flag =
#ifdef WNOHANG
WNOHANG|
#endif
#ifdef WUNTRACED
WUNTRACED|
#endif
0;
rb_scan_args(argc, argv, "11", &pid, &exc);
cpid = rb_waitpid(NUM2PIDT(pid), &status, flag);
if (cpid == -1 || cpid == 0) return Qnil;
if (!RTEST(exc)) return rb_last_status_get();
raise_from_check(cpid, status);
UNREACHABLE_RETURN(Qnil);
}
Checks the status of the child process specified by pid. Returns nil if the process is still alive.
If the process is not alive, and raise was true, a PTY::ChildExited exception will be raised. Otherwise it will return a Process::Status instance.
pid-
The process id of the process to check
raise-
If
trueand the process identified bypidis no longer alive aPTY::ChildExitedis raised.