File: C:/Ruby27-x64/share/ri/2.7.0/system/Process/detach-c.ri
U:RDoc::AnyMethod[iI"detach:ETI"Process::detach;TT:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [
I"BSome operating systems retain the status of terminated child ;TI"Eprocesses until the parent collects that status (normally using ;TI"Hsome variant of <code>wait()</code>). If the parent never collects ;TI"Gthis status, the child stays around as a <em>zombie</em> process. ;TI"HProcess::detach prevents this by setting up a separate Ruby thread ;TI"Gwhose sole job is to reap the status of the process _pid_ when it ;TI"Gterminates. Use #detach only when you do not intend to explicitly ;TI"%wait for the child to terminate.;To:RDoc::Markup::BlankLine o;
; [ I"HThe waiting thread returns the exit status of the detached process ;TI"7when it terminates, so you can use Thread#join to ;TI"Gknow the result. If specified _pid_ is not a valid child process ;TI".ID, the thread returns +nil+ immediately.;T@o;
; [I">The waiting thread has #pid method which returns the pid.;T@o;
; [I"FIn this first example, we don't reap the first child process, so ;TI":it appears as a zombie in the process status display.;T@o:RDoc::Markup::Verbatim; [
I"p1 = fork { sleep 0.1 }
;TI"p2 = fork { sleep 0.2 }
;TI"Process.waitpid(p2)
;TI"
sleep 2
;TI")system("ps -ho pid,state -p #{p1}")
;T:@format0o;
; [I"<em>produces:</em>;T@o;; [I"
27389 Z
;T;
0o;
; [I":In the next example, Process::detach is used to reap ;TI"the child automatically.;T@o;; [I"p1 = fork { sleep 0.1 }
;TI"p2 = fork { sleep 0.2 }
;TI"Process.detach(p1)
;TI"Process.waitpid(p2)
;TI"
sleep 2
;TI")system("ps -ho pid,state -p #{p1}")
;T;
0o;
; [I""<em>(produces no output)</em>;T:
@fileI"process.c;T:0@omit_headings_from_table_of_contents_below0I"%Process.detach(pid) -> thread
;T0[ I" (p1);T@?FI"Process;TcRDoc::NormalModule00