module Process
def get_exitcode(pid)
when stdin, stdout or stderr are set to custom values.
the process isn't recognized as a child process (ECHILD). This happens for example
is still running. The usual way of calling Process.wait doesn't work when
This method is very handy for finding out if a process started with Process.create
is still running. Note that the process doesn't have to be a child process.
Returns the exitcode of the process with given +pid+ or nil if the process
def get_exitcode(pid) handle = OpenProcess(PROCESS_QUERY_INFORMATION, 0, pid) if handle == INVALID_HANDLE_VALUE raise SystemCallError.new("OpenProcess", FFI.errno) end begin buf = FFI::MemoryPointer.new(:ulong, 1) unless GetExitCodeProcess(handle, buf) raise SystemCallError.new("GetExitCodeProcess", FFI.errno) end ensure CloseHandle(handle) end exitcode = buf.read_int if exitcode == STILL_ACTIVE nil else exitcode end end