D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Process
/
Filename :
detach-c.ri
back
Copy
U:RDoc::AnyMethod[iI"detach:ETI"Process::detach;TT:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [ I":Avoids the potential for a child process to become a ;TI"E{zombie process}[https://en.wikipedia.org/wiki/Zombie_process]. ;TI"GProcess.detach prevents this by setting up a separate Ruby thread ;TI"Rwhose sole job is to reap the status of the process _pid_ when it terminates.;To:RDoc::Markup::BlankLine o; ; [I"HThis method is needed only when the parent process will never wait ;TI"for the child process.;T@o; ; [I":This example does not reap the second child process; ;TI"Jthat process appears as a zombie in the process status (+ps+) output:;T@o:RDoc::Markup::Verbatim; [ I">pid = Process.spawn('ruby', '-e', 'exit 13') # => 312691 ;TI"sleep(1) ;TI"# Find zombies. ;TI"*system("ps -ho pid,state -p #{pid}") ;T:@format0o; ; [I"Output:;T@o;; [I"312716 Z ;T; 0o; ; [I"?This example also does not reap the second child process, ;TI"Hbut it does detach the process so that it does not become a zombie:;T@o;; [ I">pid = Process.spawn('ruby', '-e', 'exit 13') # => 313213 ;TI""thread = Process.detach(pid) ;TI"sleep(1) ;TI"4# => #<Process::Waiter:0x00007f038f48b838 run> ;TI"Esystem("ps -ho pid,state -p #{pid}") # Finds no zombies. ;T; 0o; ; [I"IThe waiting thread can return the pid of the detached child process:;T@o;; [I"6thread.join.pid # => 313262;T; 0: @fileI"process.c;T:0@omit_headings_from_table_of_contents_below0I"#Process.detach(pid) -> thread ;T0[ I" (p1);T@7FI"Process;TcRDoc::NormalModule00