Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
4089 lines (2316 sloc) 120 KB
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
Class: Fork
&mdash; Documentation by YARD 0.8.1
</title>
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />
<link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
<script type="text/javascript" charset="utf-8">
hasFrames = window.top.frames.main ? true : false;
relpath = '';
framesUrl = "frames.html#!" + escape(window.location.href);
</script>
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
</head>
<body>
<div id="header">
<div id="menu">
<a href="_index.html">Index (F)</a> &raquo;
<span class="title">Fork</span>
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
</div>
<div id="search">
<a class="full_list_link" id="class_list_link"
href="class_list.html">
Class List
</a>
<a class="full_list_link" id="method_list_link"
href="method_list.html">
Method List
</a>
<a class="full_list_link" id="file_list_link"
href="file_list.html">
File List
</a>
</div>
<div class="clear"></div>
</div>
<iframe id="search_frame"></iframe>
<div id="content"><h1>Class: Fork
</h1>
<dl class="box">
<dt class="r1">Inherits:</dt>
<dd class="r1">
<span class="inheritName">Object</span>
<ul class="fullTree">
<li>Object</li>
<li class="next">Fork</li>
</ul>
<a href="#" class="inheritanceTree">show all</a>
</dd>
<dt class="r2 last">Defined in:</dt>
<dd class="r2 last">lib/fork.rb<span class="defines">,<br />
lib/fork/version.rb</span>
</dd>
</dl>
<div class="clear"></div>
<h2>Overview</h2><div class="docstring">
<div class="discussion">
<div class="note notetag">
<strong>Note:</strong>
<div class='inline'><p>You should only interact between parent and fork by the means provided by the Fork
class.</p>
</div>
</div>
<p>An object representing a fork, containing data about it like pid, exit_status,
exception etc.</p>
<p>It also provides facilities for parent and child process to communicate
with each other.</p>
</div>
</div>
<div class="tags">
<div class="examples">
<p class="tag_title">Examples:</p>
<p class="example_title"><div class='inline'><p>Usage</p>
</div></p>
<pre class="example code"><span class='kw'>def</span> <span class='id identifier rubyid_fib'>fib</span><span class='lparen'>(</span><span class='id identifier rubyid_n'>n</span><span class='rparen'>)</span> <span class='id identifier rubyid_n'>n</span> <span class='op'>&lt;</span> <span class='int'>2</span> <span class='op'>?</span> <span class='id identifier rubyid_n'>n</span> <span class='op'>:</span> <span class='id identifier rubyid_fib'>fib</span><span class='lparen'>(</span><span class='id identifier rubyid_n'>n</span><span class='op'>-</span><span class='int'>1</span><span class='rparen'>)</span><span class='op'>+</span><span class='id identifier rubyid_fib'>fib</span><span class='lparen'>(</span><span class='id identifier rubyid_n'>n</span><span class='op'>-</span><span class='int'>2</span><span class='rparen'>)</span><span class='semicolon'>;</span> <span class='kw'>end</span> <span class='comment'># &lt;-- bad implementation of fibonacci
</span><span class='id identifier rubyid_fork'>fork</span> <span class='op'>=</span> <span class='const'>Fork</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='symbol'>:return</span> <span class='kw'>do</span>
<span class='id identifier rubyid_fib'>fib</span><span class='lparen'>(</span><span class='int'>35</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_fork'>fork</span><span class='period'>.</span><span class='id identifier rubyid_execute'>execute</span>
<span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Forked child process with pid </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_fork'>fork</span><span class='period'>.</span><span class='id identifier rubyid_pid'>pid</span><span class='rbrace'>}</span><span class='tstring_content'> is currently </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_fork'>fork</span><span class='period'>.</span><span class='id identifier rubyid_alive?'>alive?</span> <span class='op'>?</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>alive</span><span class='tstring_end'>'</span></span> <span class='op'>:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>dead</span><span class='tstring_end'>'</span></span><span class='rbrace'>}</span><span class='tstring_end'>&quot;</span></span>
<span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_fork'>fork</span><span class='period'>.</span><span class='id identifier rubyid_return_value'>return_value</span> <span class='comment'># this blocks, until the fork finished, and returns the last value</span></pre>
<p class="example_title"><div class='inline'><p>The same, but a bit simpler</p>
</div></p>
<pre class="example code"><span class='kw'>def</span> <span class='id identifier rubyid_fib'>fib</span><span class='lparen'>(</span><span class='id identifier rubyid_n'>n</span><span class='rparen'>)</span> <span class='id identifier rubyid_n'>n</span> <span class='op'>&lt;</span> <span class='int'>2</span> <span class='op'>?</span> <span class='id identifier rubyid_n'>n</span> <span class='op'>:</span> <span class='id identifier rubyid_fib'>fib</span><span class='lparen'>(</span><span class='id identifier rubyid_n'>n</span><span class='op'>-</span><span class='int'>1</span><span class='rparen'>)</span><span class='op'>+</span><span class='id identifier rubyid_fib'>fib</span><span class='lparen'>(</span><span class='id identifier rubyid_n'>n</span><span class='op'>-</span><span class='int'>2</span><span class='rparen'>)</span><span class='semicolon'>;</span> <span class='kw'>end</span> <span class='comment'># &lt;-- bad implementation of fibonacci
</span><span class='id identifier rubyid_fork'>fork</span> <span class='op'>=</span> <span class='const'>Fork</span><span class='period'>.</span><span class='id identifier rubyid_execute'>execute</span> <span class='symbol'>:return</span> <span class='kw'>do</span>
<span class='id identifier rubyid_fib'>fib</span><span class='lparen'>(</span><span class='int'>35</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_fork'>fork</span><span class='period'>.</span><span class='id identifier rubyid_return_value'>return_value</span> <span class='comment'># this blocks, until the fork finished, and returns the last value</span></pre>
<p class="example_title"><div class='inline'><p>And the simplest version, if all you care about is the return value</p>
</div></p>
<pre class="example code"><span class='kw'>def</span> <span class='id identifier rubyid_fib'>fib</span><span class='lparen'>(</span><span class='id identifier rubyid_n'>n</span><span class='rparen'>)</span> <span class='id identifier rubyid_n'>n</span> <span class='op'>&lt;</span> <span class='int'>2</span> <span class='op'>?</span> <span class='id identifier rubyid_n'>n</span> <span class='op'>:</span> <span class='id identifier rubyid_fib'>fib</span><span class='lparen'>(</span><span class='id identifier rubyid_n'>n</span><span class='op'>-</span><span class='int'>1</span><span class='rparen'>)</span><span class='op'>+</span><span class='id identifier rubyid_fib'>fib</span><span class='lparen'>(</span><span class='id identifier rubyid_n'>n</span><span class='op'>-</span><span class='int'>2</span><span class='rparen'>)</span><span class='semicolon'>;</span> <span class='kw'>end</span> <span class='comment'># &lt;-- bad implementation of fibonacci
</span><span class='id identifier rubyid_future'>future</span> <span class='op'>=</span> <span class='const'>Fork</span><span class='period'>.</span><span class='id identifier rubyid_future'>future</span> <span class='kw'>do</span>
<span class='id identifier rubyid_fib'>fib</span><span class='lparen'>(</span><span class='int'>35</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_future'>future</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span> <span class='comment'># this blocks, until the fork finished, and returns the last value</span></pre>
</div>
</div><h2>Defined Under Namespace</h2>
<p class="children">
<strong class="classes">Classes:</strong> <span class='object_link'><a href="Fork/FlagNotSpecified.html" title="Fork::FlagNotSpecified (class)">FlagNotSpecified</a></span>, <span class='object_link'><a href="Fork/NotRunning.html" title="Fork::NotRunning (class)">NotRunning</a></span>, <span class='object_link'><a href="Fork/UndumpableException.html" title="Fork::UndumpableException (class)">UndumpableException</a></span>
</p>
<h2>Constant Summary</h2>
<dl class="constants">
<dt id="IgnoreExceptions-constant" class="">IgnoreExceptions =
<div class="docstring">
<div class="discussion">
<p>Exceptions that have to be ignored in the child&rsquo;s handling of exceptions</p>
</div>
</div>
<div class="tags">
</div>
</dt>
<dd><pre class="code"><span class='lbracket'>[</span><span class='op'>::</span><span class='const'>SystemExit</span><span class='rbracket'>]</span></pre></dd>
<dt id="DefaultFlags-constant" class="">DefaultFlags =
<div class="docstring">
<div class="discussion">
<p>The default flags Fork#initialize uses</p>
</div>
</div>
<div class="tags">
</div>
</dt>
<dd><pre class="code"><span class='const'>Hash</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid__hash'>_hash</span><span class='comma'>,</span> <span class='id identifier rubyid_key'>key</span><span class='op'>|</span> <span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Unknown flag </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_key'>key</span><span class='rbrace'>}</span><span class='tstring_end'>&quot;</span></span> <span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_merge'>merge</span><span class='lparen'>(</span><span class='lbrace'>{</span>
<span class='symbol'>:exceptions</span> <span class='op'>=&gt;</span> <span class='kw'>false</span><span class='comma'>,</span>
<span class='symbol'>:death_notice</span> <span class='op'>=&gt;</span> <span class='kw'>false</span><span class='comma'>,</span>
<span class='symbol'>:return</span> <span class='op'>=&gt;</span> <span class='kw'>false</span><span class='comma'>,</span>
<span class='symbol'>:to_fork</span> <span class='op'>=&gt;</span> <span class='kw'>false</span><span class='comma'>,</span>
<span class='symbol'>:from_fork</span> <span class='op'>=&gt;</span> <span class='kw'>false</span><span class='comma'>,</span>
<span class='symbol'>:ctrl</span> <span class='op'>=&gt;</span> <span class='kw'>false</span><span class='comma'>,</span>
<span class='rbrace'>}</span><span class='rparen'>)</span></pre></dd>
<dt id="Version-constant" class="">Version =
<div class="docstring">
<div class="discussion">
<p>The currently required version of the Fork gem</p>
</div>
</div>
<div class="tags">
</div>
</dt>
<dd><pre class="code"><span class='const'>Gem</span><span class='op'>::</span><span class='const'>Version</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>0.0.1</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span></pre></dd>
</dl>
<h2>Instance Attribute Summary <small>(<a href="#" class="summary_toggle">collapse</a>)</small></h2>
<ul class="summary">
<li class="public ">
<span class="summary_signature">
<a href="#ctrl-instance_method" title="#ctrl (instance method)">- (Object) <strong>ctrl</strong> </a>
</span>
<span class="note title readonly">readonly</span>
<span class="summary_desc"><div class='inline'><p>Control IO (reserved for exception and death-notice passing).</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#pid-instance_method" title="#pid (instance method)">- (Object) <strong>pid</strong> </a>
</span>
<span class="note title readonly">readonly</span>
<span class="summary_desc"><div class='inline'><p>The process id of the fork.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#readable_io-instance_method" title="#readable_io (instance method)">- (Object) <strong>readable_io</strong> </a>
</span>
<span class="note title readonly">readonly</span>
<span class="summary_desc"><div class='inline'><p>Readable IO
Allows the parent to read data from the fork, and the fork to read data from the
parent.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#writable_io-instance_method" title="#writable_io (instance method)">- (Object) <strong>writable_io</strong> </a>
</span>
<span class="note title readonly">readonly</span>
<span class="summary_desc"><div class='inline'><p>Writable IO
Allows the parent to write data to the fork, and the fork to write data to the parent.</p>
</div></span>
</li>
</ul>
<h2>
Class Method Summary
<small>(<a href="#" class="summary_toggle">collapse</a>)</small>
</h2>
<ul class="summary">
<li class="public ">
<span class="summary_signature">
<a href="#execute-class_method" title="execute (class method)">+ (Object) <strong>execute</strong>(*args, &amp;block) </a>
</span>
<span class="summary_desc"><div class='inline'><p>Create a Fork instance and immediatly start executing it.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#future-class_method" title="future (class method)">+ (Proc) <strong>future</strong>(*args) </a>
</span>
<span class="summary_desc"><div class='inline'><p>A simple forked-future implementation.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#read_marshalled-class_method" title="read_marshalled (class method)">+ (Object) <strong>read_marshalled</strong>(io) </a>
</span>
<span class="summary_desc"><div class='inline'><p>Reads an object sent via Fork.read_marshalled from the passed io.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#return-class_method" title="return (class method)">+ (Object) <strong>return</strong>(*args) </a>
</span>
<span class="summary_desc"><div class='inline'><p>A simple forked-callback implementation.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#write_marshalled-class_method" title="write_marshalled (class method)">+ (Integer) <strong>write_marshalled</strong>(io, obj) </a>
</span>
<span class="summary_desc"><div class='inline'><p>Writes an object in serialized form to the passed IO.</p>
</div></span>
</li>
</ul>
<h2>
Instance Method Summary
<small>(<a href="#" class="summary_toggle">collapse</a>)</small>
</h2>
<ul class="summary">
<li class="public ">
<span class="summary_signature">
<a href="#alive%3F-instance_method" title="#alive? (instance method)">- (Boolean) <strong>alive?</strong> </a>
</span>
<span class="summary_desc"><div class='inline'><p>Whether this fork is still running (= is alive) or already exited.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#clone-instance_method" title="#clone (instance method)">- (Object) <strong>clone</strong> </a>
</span>
<span class="summary_desc"><div class='inline'><p>Cloning a fork instance is prohibited.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#close-instance_method" title="#close (instance method)">- (Object) <strong>close</strong> </a>
</span>
<span class="summary_desc"><div class='inline'><p>Close all IOs.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#complete%21-instance_method" title="#complete! (instance method)">- (Object) <strong>complete!</strong>(pid, readable_io, writable_io, ctrl_io) </a>
</span>
<span class="summary_desc"><div class='inline'><p>Sets the io to communicate with the parent/child.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#dead%3F-instance_method" title="#dead? (instance method)">- (Boolean) <strong>dead?</strong> </a>
</span>
<span class="summary_desc"><div class='inline'><p>Whether this fork is still running or already exited (= is dead).</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#death_notice%3F-instance_method" title="#death_notice? (instance method)">- (Boolean) <strong>death_notice?</strong> </a>
</span>
<span class="summary_desc"><div class='inline'><p>Whether this fork sends a death notice to the parent.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#dup-instance_method" title="#dup (instance method)">- (Object) <strong>dup</strong> </a>
</span>
<span class="summary_desc"><div class='inline'><p>Duping a fork instance is prohibited.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#exception-instance_method" title="#exception (instance method)">- (Object) <strong>exception</strong>(blocking = true) </a>
</span>
<span class="summary_desc"><div class='inline'><p>The exception that terminated the fork
Requires the :exceptions flag to be set when creating the fork.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#execute-instance_method" title="#execute (instance method)">- (self) <strong>execute</strong> </a>
</span>
<span class="summary_desc"><div class='inline'><p>Creates the fork (subprocess) and starts executing it.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#exit_status-instance_method" title="#exit_status (instance method)">- (Object) <strong>exit_status</strong>(blocking = true) </a>
</span>
<span class="summary_desc"><div class='inline'><p>The exit status of this fork.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#failure%3F-instance_method" title="#failure? (instance method)">- (Boolean) <strong>failure?</strong> </a>
</span>
<span class="summary_desc"><div class='inline'><p>Blocks until the fork has exited.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#fork%3F-instance_method" title="#fork? (instance method)">- (Boolean) <strong>fork?</strong> </a>
</span>
<span class="summary_desc"><div class='inline'><p>Whether the current code is executed in the fork, as opposed to the parent.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#gets-instance_method" title="#gets (instance method)">- (String<sup>?</sup>) <strong>gets</strong>(*args) </a>
</span>
<span class="summary_desc"><div class='inline'><p>In the parent process: read data from the fork.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#handle_exceptions%3F-instance_method" title="#handle_exceptions? (instance method)">- (Boolean) <strong>handle_exceptions?</strong> </a>
</span>
<span class="summary_desc"><div class='inline'><p>Whether this fork sends the final exception to the parent.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#has_ctrl%3F-instance_method" title="#has_ctrl? (instance method)">- (Boolean) <strong>has_ctrl?</strong> </a>
</span>
<span class="summary_desc"><div class='inline'><p>Whether parent and fork use a control-io.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#has_in%3F-instance_method" title="#has_in? (instance method)">- (Boolean) <strong>has_in?</strong> </a>
</span>
<span class="summary_desc"><div class='inline'><p>Whether the other process can write to this process.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#has_out%3F-instance_method" title="#has_out? (instance method)">- (Boolean) <strong>has_out?</strong> </a>
</span>
<span class="summary_desc"><div class='inline'><p>Whether this process can write to the other process.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#initialize-instance_method" title="#initialize (instance method)">- (Fork) <strong>initialize</strong>(*flags, &amp;block) </a>
</span>
<span class="note title constructor">constructor</span>
<span class="summary_desc"><div class='inline'><p>Create a new Fork instance.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#inspect-instance_method" title="#inspect (instance method)">- (Object) <strong>inspect</strong> </a>
</span>
<span class="summary_desc"><div class='inline'><p>See Object#inspect.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#kill-instance_method" title="#kill (instance method)">- (Object) <strong>kill</strong> </a>
</span>
<span class="summary_desc"><div class='inline'><p>Sends the (SIG)HUP signal to this fork.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#kill%21-instance_method" title="#kill! (instance method)">- (Object) <strong>kill!</strong> </a>
</span>
<span class="summary_desc"><div class='inline'><p>Sends the (SIG)KILL signal to this fork.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#parent%3F-instance_method" title="#parent? (instance method)">- (Boolean) <strong>parent?</strong> </a>
</span>
<span class="summary_desc"><div class='inline'><p>Whether the current code is executed in the parent of the fork.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#process_status-instance_method" title="#process_status (instance method)">- (Object) <strong>process_status</strong>(blocking = true) </a>
</span>
<span class="summary_desc"><div class='inline'><p>Process::Status for dead forks, nil for live forks.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#puts-instance_method" title="#puts (instance method)">- (nil) <strong>puts</strong>(*args) </a>
</span>
<span class="summary_desc"><div class='inline'><p>In the parent process: Write to the fork.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#read-instance_method" title="#read (instance method)">- (String<sup>?</sup>) <strong>read</strong>(*args) </a>
</span>
<span class="summary_desc"><div class='inline'><p>In the parent process: read data from the fork.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#read_nonblock-instance_method" title="#read_nonblock (instance method)">- (String<sup>?</sup>) <strong>read_nonblock</strong>(*args) </a>
</span>
<span class="summary_desc"><div class='inline'><p>In the parent process: read data from the fork.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#read_remaining_ctrl-instance_method" title="#read_remaining_ctrl (instance method)">- (self) <strong>read_remaining_ctrl</strong>(_wait_upon_eof = true) </a>
</span>
<span class="summary_desc"><div class='inline'><p>Read a single instruction sent via @ctrl, used by :exception, :death_notice and
:return_value.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#receive_object-instance_method" title="#receive_object (instance method)">- (Object) <strong>receive_object</strong> </a>
</span>
<span class="summary_desc"><div class='inline'><p>In the parent process: read on object sent by the fork.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#return_value-instance_method" title="#return_value (instance method)">- (Object) <strong>return_value</strong>(blocking = true) </a>
</span>
<span class="summary_desc"><div class='inline'><p>Blocks until the fork returns.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#returns%3F-instance_method" title="#returns? (instance method)">- (Boolean) <strong>returns?</strong> </a>
</span>
<span class="summary_desc"><div class='inline'><p>Whether this forks terminal value is returned to the parent.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#send_object-instance_method" title="#send_object (instance method)">- (Object) <strong>send_object</strong>(obj) </a>
</span>
<span class="summary_desc"><div class='inline'><p>Sends an object to the parent process.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#signal-instance_method" title="#signal (instance method)">- (Object) <strong>signal</strong>(sig) </a>
</span>
<span class="summary_desc"><div class='inline'><p>Sends the given signal to this fork
See Fork#kill, Fork#kill!, Process.kill.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#success%3F-instance_method" title="#success? (instance method)">- (Boolean) <strong>success?</strong> </a>
</span>
<span class="summary_desc"><div class='inline'><p>Blocks until the fork has exited.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#wait-instance_method" title="#wait (instance method)">- (Object) <strong>wait</strong> </a>
</span>
<span class="summary_desc"><div class='inline'><p>Wait for this fork to terminate.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#write-instance_method" title="#write (instance method)">- (Integer) <strong>write</strong>(*args) </a>
</span>
<span class="summary_desc"><div class='inline'><p>In the parent process: Write to the fork.</p>
</div></span>
</li>
</ul>
<div id="constructor_details" class="method_details_list">
<h2>Constructor Details</h2>
<div class="method_details first">
<h3 class="signature first" id="initialize-instance_method">
- (<tt><span class='object_link'><a href="" title="Fork (class)">Fork</a></span></tt>) <strong>initialize</strong>(*flags, &amp;block)
</h3><div class="docstring">
<div class="discussion">
<p>Create a new Fork instance.
The subprocess is not immediatly executed, you must invoke #execute on the Fork
instance in order to get it executed. Only then #pid, #in, #out and #ctrl will be
available. Also all IO related methods won&rsquo;t work before that.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>flags</span>
<span class='type'>(<tt>Symbol</tt>, <tt>Hash</tt>)</span>
&mdash;
<div class='inline'><p>Tells the fork what facilities to provide. You can pass the flags either as a list
of symbols, or as a Hash, or even mixed (the hash must be the last argument then).</p>
<p>Valid flags are:
* :return Make the value of the last expression (return value) available to
the parent process
* :exceptions Pass exceptions of the fork to the parent, making it available via
Fork#exception
* :death_notice Send the parent process an information when done processing
* :to_fork You can write to the Fork from the parent process, and read in the
child process
* :from_fork You can read from the Fork in the parent process and write in the
child process
* :ctrl Provides an additional IO for control mechanisms</p>
<p>Some flags implicitly set other flags. For example, :return will set :exceptions and
:ctrl, :exceptions will set :ctrl and :death_notice will also set :ctrl.</p>
</div>
</li>
</ul>
<p class="tag_title">Raises:</p>
<ul class="raise">
<li>
<span class='type'>(<tt>ArgumentError</tt>)</span>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/fork.rb', line 201</span>
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_flags'>flags</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>No block given</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_block'>block</span>
<span class='kw'>if</span> <span class='id identifier rubyid_flags'>flags</span><span class='period'>.</span><span class='id identifier rubyid_last'>last</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span> <span class='kw'>then</span>
<span class='ivar'>@flags</span> <span class='op'>=</span> <span class='const'>DefaultFlags</span><span class='period'>.</span><span class='id identifier rubyid_merge'>merge</span><span class='lparen'>(</span><span class='id identifier rubyid_flags'>flags</span><span class='period'>.</span><span class='id identifier rubyid_pop'>pop</span><span class='rparen'>)</span>
<span class='kw'>else</span>
<span class='ivar'>@flags</span> <span class='op'>=</span> <span class='const'>DefaultFlags</span><span class='period'>.</span><span class='id identifier rubyid_dup'>dup</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_flags'>flags</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_flag'>flag</span><span class='op'>|</span>
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Unknown flag </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_flag'>flag</span><span class='period'>.</span><span class='id identifier rubyid_inspect'>inspect</span><span class='rbrace'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>unless</span> <span class='ivar'>@flags</span><span class='period'>.</span><span class='id identifier rubyid_has_key?'>has_key?</span><span class='lparen'>(</span><span class='id identifier rubyid_flag'>flag</span><span class='rparen'>)</span>
<span class='ivar'>@flags</span><span class='lbracket'>[</span><span class='id identifier rubyid_flag'>flag</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='kw'>true</span>
<span class='kw'>end</span>
<span class='ivar'>@flags</span><span class='lbracket'>[</span><span class='symbol'>:ctrl</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='kw'>true</span> <span class='kw'>if</span> <span class='ivar'>@flags</span><span class='period'>.</span><span class='id identifier rubyid_values_at'>values_at</span><span class='lparen'>(</span><span class='symbol'>:exceptions</span><span class='comma'>,</span> <span class='symbol'>:death_notice</span><span class='comma'>,</span> <span class='symbol'>:return</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_any?'>any?</span>
<span class='ivar'>@flags</span><span class='lbracket'>[</span><span class='symbol'>:exceptions</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='kw'>true</span> <span class='kw'>if</span> <span class='ivar'>@flags</span><span class='lbracket'>[</span><span class='symbol'>:return</span><span class='rbracket'>]</span>
<span class='ivar'>@parent</span> <span class='op'>=</span> <span class='kw'>true</span>
<span class='ivar'>@alive</span> <span class='op'>=</span> <span class='kw'>nil</span>
<span class='ivar'>@pid</span> <span class='op'>=</span> <span class='kw'>nil</span>
<span class='ivar'>@process_status</span> <span class='op'>=</span> <span class='kw'>nil</span>
<span class='ivar'>@readable_io</span> <span class='op'>=</span> <span class='kw'>nil</span>
<span class='ivar'>@writable_io</span> <span class='op'>=</span> <span class='kw'>nil</span>
<span class='ivar'>@ctrl</span> <span class='op'>=</span> <span class='kw'>nil</span>
<span class='ivar'>@block</span> <span class='op'>=</span> <span class='id identifier rubyid_block'>block</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
</div>
<div id="instance_attr_details" class="attr_details">
<h2>Instance Attribute Details</h2>
<span id=""></span>
<span id="ctrl-instance_method"></span>
<div class="method_details first">
<h3 class="signature first" id="ctrl-instance_method">
- (<tt>Object</tt>) <strong>ctrl</strong> <span class="extras">(readonly)</span>
</h3><div class="docstring">
<div class="discussion">
<p>Control IO (reserved for exception and death-notice passing)</p>
</div>
</div>
<div class="tags">
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
176
177
178</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/fork.rb', line 176</span>
<span class='kw'>def</span> <span class='id identifier rubyid_ctrl'>ctrl</span>
<span class='ivar'>@ctrl</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<span id=""></span>
<span id="pid-instance_method"></span>
<div class="method_details ">
<h3 class="signature " id="pid-instance_method">
- (<tt>Object</tt>) <strong>pid</strong> <span class="extras">(readonly)</span>
</h3><div class="docstring">
<div class="discussion">
<div class="note notetag">
<strong>Note:</strong>
<div class='inline'><p>You <em>must not</em> directly interact with the forked process using the pid.
This may lead to unexpected conflicts with Fork&rsquo;s internal mechanisms.</p>
</div>
</div>
<p>The process id of the fork</p>
</div>
</div>
<div class="tags">
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
162
163
164</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/fork.rb', line 162</span>
<span class='kw'>def</span> <span class='id identifier rubyid_pid'>pid</span>
<span class='ivar'>@pid</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<span id=""></span>
<span id="readable_io-instance_method"></span>
<div class="method_details ">
<h3 class="signature " id="readable_io-instance_method">
- (<tt>Object</tt>) <strong>readable_io</strong> <span class="extras">(readonly)</span>
</h3><div class="docstring">
<div class="discussion">
<p>Readable IO
Allows the parent to read data from the fork, and the fork to read data from the
parent.
Requires the :to_fork and/or :from_fork flag to be set.</p>
</div>
</div>
<div class="tags">
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
168
169
170</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/fork.rb', line 168</span>
<span class='kw'>def</span> <span class='id identifier rubyid_readable_io'>readable_io</span>
<span class='ivar'>@readable_io</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<span id=""></span>
<span id="writable_io-instance_method"></span>
<div class="method_details ">
<h3 class="signature " id="writable_io-instance_method">
- (<tt>Object</tt>) <strong>writable_io</strong> <span class="extras">(readonly)</span>
</h3><div class="docstring">
<div class="discussion">
<p>Writable IO
Allows the parent to write data to the fork, and the fork to write data to the parent.
Requires the :to_fork and/or :from_fork flag to be set.</p>
</div>
</div>
<div class="tags">
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
173
174
175</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/fork.rb', line 173</span>
<span class='kw'>def</span> <span class='id identifier rubyid_writable_io'>writable_io</span>
<span class='ivar'>@writable_io</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
</div>
<div id="class_method_details" class="method_details_list">
<h2>Class Method Details</h2>
<div class="method_details first">
<h3 class="signature first" id="execute-class_method">
+ (<tt>Object</tt>) <strong>execute</strong>(*args, &amp;block)
</h3><div class="docstring">
<div class="discussion">
<p>Create a Fork instance and immediatly start executing it.
Equivalent to just call Fork.new(*args) { &hellip; }.execute</p>
<p>Returns the Fork instance.
See Fork#initialize</p>
</div>
</div>
<div class="tags">
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
153
154
155</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/fork.rb', line 153</span>
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_execute'>execute</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_execute'>execute</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="future-class_method">
+ (<tt>Proc</tt>) <strong>future</strong>(*args)
</h3><div class="docstring">
<div class="discussion">
<p>A simple forked-future implementation. Will process the block in a fork,
blocks upon request of the result until the result is present.
If the forked code raises an exception, invoking call on the proc will raise that
exception in the parent process.</p>
</div>
</div>
<div class="tags">
<div class="examples">
<p class="tag_title">Examples:</p>
<p class="example_title"><div class='inline'><p>Usage</p>
</div></p>
<pre class="example code"><span class='comment'># A
</span><span class='const'>Fork</span><span class='period'>.</span><span class='id identifier rubyid_future'>future</span> <span class='lbrace'>{</span> <span class='int'>1</span> <span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span> <span class='comment'># =&gt; 1
</span>
<span class='comment'># B
</span><span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='const'>Fork</span><span class='period'>.</span><span class='id identifier rubyid_future'>future</span> <span class='lbrace'>{</span> <span class='id identifier rubyid_sleep'>sleep</span> <span class='int'>2</span><span class='semicolon'>;</span> <span class='int'>1</span> <span class='rbrace'>}</span> <span class='comment'># assume a complex computation instead of sleep(2)
</span><span class='id identifier rubyid_sleep'>sleep</span> <span class='int'>2</span> <span class='comment'># assume another complex computation
</span><span class='id identifier rubyid_start'>start</span> <span class='op'>=</span> <span class='const'>Time</span><span class='period'>.</span><span class='id identifier rubyid_now'>now</span>
<span class='id identifier rubyid_result'>result</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span> <span class='comment'># =&gt; 1
</span><span class='id identifier rubyid_elapsed_time'>elapsed_time</span> <span class='op'>=</span> <span class='const'>Time</span><span class='period'>.</span><span class='id identifier rubyid_now'>now</span><span class='op'>-</span><span class='id identifier rubyid_start'>start</span> <span class='comment'># =&gt; &lt;1s as the work was done parallely</span></pre>
</div>
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>args</span>
<span class='type'></span>
&mdash;
<div class='inline'><p>All parameters passed to Fork.future are passed on to the block.</p>
</div>
</li>
</ul>
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>Proc</tt>)</span>
&mdash;
<div class='inline'><p>A lambda which upon invoking #call will block until the result of the block is
calculated.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
118
119
120
121
122
123
124</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/fork.rb', line 118</span>
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_future'>future</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span>
<span class='id identifier rubyid_obj'>obj</span> <span class='op'>=</span> <span class='id identifier rubyid_execute'>execute</span> <span class='symbol'>:return</span> <span class='op'>=&gt;</span> <span class='kw'>true</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_parent'>parent</span><span class='op'>|</span>
<span class='kw'>yield</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_lambda'>lambda</span> <span class='lbrace'>{</span> <span class='id identifier rubyid_obj'>obj</span><span class='period'>.</span><span class='id identifier rubyid_return_value'>return_value</span> <span class='rbrace'>}</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="read_marshalled-class_method">
+ (<tt>Object</tt>) <strong>read_marshalled</strong>(io)
</h3><div class="docstring">
<div class="discussion">
<p>Reads an object sent via Fork.read_marshalled from the passed io.
Raises EOFError if the io was closed on the remote end.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>Object</tt>)</span>
&mdash;
<div class='inline'><p>The deserialized object which was sent through the IO</p>
</div>
</li>
</ul>
<p class="tag_title">Raises:</p>
<ul class="raise">
<li>
<span class='type'>(<tt>EOFError</tt>)</span>
</li>
</ul>
<p class="tag_title">See Also:</p>
<ul class="see">
<li><span class='object_link'><a href="#write_marshalled-class_method" title="Fork.write_marshalled (method)">Implements the opposite operation: writing an object on an IO.</a></span></li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
75
76
77
78
79
80
81</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/fork.rb', line 75</span>
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_read_marshalled'>read_marshalled</span><span class='lparen'>(</span><span class='id identifier rubyid_io'>io</span><span class='rparen'>)</span>
<span class='id identifier rubyid_size'>size</span> <span class='op'>=</span> <span class='id identifier rubyid_io'>io</span><span class='period'>.</span><span class='id identifier rubyid_read'>read</span><span class='lparen'>(</span><span class='int'>4</span><span class='rparen'>)</span>
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>EOFError</span> <span class='kw'>unless</span> <span class='id identifier rubyid_size'>size</span>
<span class='id identifier rubyid_size'>size</span> <span class='op'>=</span> <span class='id identifier rubyid_size'>size</span><span class='period'>.</span><span class='id identifier rubyid_unpack'>unpack</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>I</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span>
<span class='id identifier rubyid_marshalled'>marshalled</span> <span class='op'>=</span> <span class='id identifier rubyid_io'>io</span><span class='period'>.</span><span class='id identifier rubyid_read'>read</span><span class='lparen'>(</span><span class='id identifier rubyid_size'>size</span><span class='rparen'>)</span>
<span class='const'>Marshal</span><span class='period'>.</span><span class='id identifier rubyid_load'>load</span><span class='lparen'>(</span><span class='id identifier rubyid_marshalled'>marshalled</span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="return-class_method">
+ (<tt>Object</tt>) <strong>return</strong>(*args)
</h3><div class="docstring">
<div class="discussion">
<p>A simple forked-callback implementation. Will process the block in a fork,
block until it has finished processing and returns the return value of the
block.
This can be useful if you want to process something that will (or might)
irreversibly corrupt the environment. Doing that in a subprocess will leave
the parent untouched.</p>
</div>
</div>
<div class="tags">
<div class="examples">
<p class="tag_title">Examples:</p>
<p class="example_title"><div class='inline'><p>Usage</p>
</div></p>
<pre class="example code"><span class='const'>Fork</span><span class='period'>.</span><span class='id identifier rubyid_return'>return</span> <span class='lbrace'>{</span> <span class='int'>1</span> <span class='rbrace'>}</span> <span class='comment'># =&gt; 1</span></pre>
</div>
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>args</span>
<span class='type'></span>
&mdash;
<div class='inline'><p>All parameters passed to Fork.return are passed on to the block.</p>
</div>
</li>
</ul>
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'></span>
<div class='inline'><p>Returns the result of the block.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
141
142
143
144
145
146</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/fork.rb', line 141</span>
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='kw'>return</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span>
<span class='id identifier rubyid_obj'>obj</span> <span class='op'>=</span> <span class='id identifier rubyid_execute'>execute</span> <span class='symbol'>:return</span> <span class='op'>=&gt;</span> <span class='kw'>true</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_parent'>parent</span><span class='op'>|</span>
<span class='kw'>yield</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_obj'>obj</span><span class='period'>.</span><span class='id identifier rubyid_return_value'>return_value</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="write_marshalled-class_method">
+ (<tt>Integer</tt>) <strong>write_marshalled</strong>(io, obj)
</h3><div class="docstring">
<div class="discussion">
<p>Writes an object in serialized form to the passed IO.
Important: certain objects are not marshallable, e.g. IOs, Procs and
anonymous modules and classes.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>Integer</tt>)</span>
&mdash;
<div class='inline'><p>The number of bytes written to the IO (see IO#write)</p>
</div>
</li>
</ul>
<p class="tag_title">See Also:</p>
<ul class="see">
<li><span class='object_link'><a href="#read_marshalled-class_method" title="Fork.read_marshalled (method)">Implements the opposite operation: writing an object on an IO.</a></span></li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
90
91
92
93
94</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/fork.rb', line 90</span>
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_write_marshalled'>write_marshalled</span><span class='lparen'>(</span><span class='id identifier rubyid_io'>io</span><span class='comma'>,</span> <span class='id identifier rubyid_obj'>obj</span><span class='rparen'>)</span>
<span class='id identifier rubyid_marshalled'>marshalled</span> <span class='op'>=</span> <span class='const'>Marshal</span><span class='period'>.</span><span class='id identifier rubyid_dump'>dump</span><span class='lparen'>(</span><span class='id identifier rubyid_obj'>obj</span><span class='rparen'>)</span>
<span class='id identifier rubyid_io'>io</span><span class='period'>.</span><span class='id identifier rubyid_write'>write</span><span class='lparen'>(</span><span class='lbracket'>[</span><span class='id identifier rubyid_marshalled'>marshalled</span><span class='period'>.</span><span class='id identifier rubyid_size'>size</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_pack'>pack</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>I</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
<span class='id identifier rubyid_io'>io</span><span class='period'>.</span><span class='id identifier rubyid_write'>write</span><span class='lparen'>(</span><span class='id identifier rubyid_marshalled'>marshalled</span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
</div>
<div id="instance_method_details" class="method_details_list">
<h2>Instance Method Details</h2>
<div class="method_details first">
<h3 class="signature first" id="alive?-instance_method">
- (<tt>Boolean</tt>) <strong>alive?</strong>
</h3><div class="docstring">
<div class="discussion">
<p>Whether this fork is still running (= is alive) or already exited.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>Boolean</tt>)</span>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
362
363
364</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/fork.rb', line 362</span>
<span class='kw'>def</span> <span class='id identifier rubyid_alive?'>alive?</span>
<span class='ivar'>@pid</span> <span class='op'>&amp;&amp;</span> <span class='op'>!</span><span class='id identifier rubyid_exit_status'>exit_status</span><span class='lparen'>(</span><span class='kw'>false</span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="clone-instance_method">
- (<tt>Object</tt>) <strong>clone</strong>
</h3><div class="docstring">
<div class="discussion">
<p>Cloning a fork instance is prohibited. See Object#clone.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Raises:</p>
<ul class="raise">
<li>
<span class='type'>(<tt>TypeError</tt>)</span>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
557
558
559</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/fork.rb', line 557</span>
<span class='kw'>def</span> <span class='id identifier rubyid_clone'>clone</span> <span class='comment'># :nodoc:
</span> <span class='id identifier rubyid_raise'>raise</span> <span class='const'>TypeError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>can't clone </span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='rbrace'>}</span><span class='tstring_end'>&quot;</span></span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="close-instance_method">
- (<tt>Object</tt>) <strong>close</strong>
</h3><div class="docstring">
<div class="discussion">
<p>Close all IOs</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Raises:</p>
<ul class="raise">
<li>
<span class='type'>(<tt><span class='object_link'><a href="Fork/NotRunning.html" title="Fork::NotRunning (class)">NotRunning</a></span></tt>)</span>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
542
543
544
545
546
547</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/fork.rb', line 542</span>
<span class='kw'>def</span> <span class='id identifier rubyid_close'>close</span> <span class='comment'># :nodoc:
</span> <span class='id identifier rubyid_raise'>raise</span> <span class='const'>NotRunning</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Fork is not running yet, you must invoke #execute first.</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>unless</span> <span class='ivar'>@pid</span>
<span class='ivar'>@readable_io</span><span class='period'>.</span><span class='id identifier rubyid_close'>close</span> <span class='kw'>if</span> <span class='ivar'>@readable_io</span>
<span class='ivar'>@writable_io</span><span class='period'>.</span><span class='id identifier rubyid_close'>close</span> <span class='kw'>if</span> <span class='ivar'>@writable_io</span>
<span class='ivar'>@ctrl</span><span class='period'>.</span><span class='id identifier rubyid_close'>close</span> <span class='kw'>if</span> <span class='ivar'>@ctrl</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="complete!-instance_method">
- (<tt>Object</tt>) <strong>complete!</strong>(pid, readable_io, writable_io, ctrl_io)
</h3><div class="docstring">
<div class="discussion">
<p>Sets the io to communicate with the parent/child</p>
</div>
</div>
<div class="tags">
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
298
299
300
301
302
303
304</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/fork.rb', line 298</span>
<span class='kw'>def</span> <span class='id identifier rubyid_complete!'>complete!</span><span class='lparen'>(</span><span class='id identifier rubyid_pid'>pid</span><span class='comma'>,</span> <span class='id identifier rubyid_readable_io'>readable_io</span><span class='comma'>,</span> <span class='id identifier rubyid_writable_io'>writable_io</span><span class='comma'>,</span> <span class='id identifier rubyid_ctrl_io'>ctrl_io</span><span class='rparen'>)</span> <span class='comment'># :nodoc:
</span> <span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Can't call complete! more than once</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@pid</span>
<span class='ivar'>@pid</span> <span class='op'>=</span> <span class='id identifier rubyid_pid'>pid</span>
<span class='ivar'>@readable_io</span> <span class='op'>=</span> <span class='id identifier rubyid_readable_io'>readable_io</span>
<span class='ivar'>@writable_io</span> <span class='op'>=</span> <span class='id identifier rubyid_writable_io'>writable_io</span>
<span class='ivar'>@ctrl</span> <span class='op'>=</span> <span class='id identifier rubyid_ctrl_io'>ctrl_io</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="dead?-instance_method">
- (<tt>Boolean</tt>) <strong>dead?</strong>
</h3><div class="docstring">
<div class="discussion">
<p>Whether this fork is still running or already exited (= is dead).</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>Boolean</tt>)</span>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
367
368
369</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/fork.rb', line 367</span>
<span class='kw'>def</span> <span class='id identifier rubyid_dead?'>dead?</span>
<span class='op'>!</span><span class='id identifier rubyid_alive?'>alive?</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="death_notice?-instance_method">
- (<tt>Boolean</tt>) <strong>death_notice?</strong>
</h3><div class="docstring">
<div class="discussion">
<p>Whether this fork sends a death notice to the parent</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>Boolean</tt>)</span>
&mdash;
<div class='inline'><p>Whether this fork sends a death notice to the parent</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
261
262
263</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/fork.rb', line 261</span>
<span class='kw'>def</span> <span class='id identifier rubyid_death_notice?'>death_notice?</span>
<span class='ivar'>@flags</span><span class='lbracket'>[</span><span class='symbol'>:death_notice</span><span class='rbracket'>]</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="dup-instance_method">
- (<tt>Object</tt>) <strong>dup</strong>
</h3><div class="docstring">
<div class="discussion">
<p>Duping a fork instance is prohibited. See Object#dup.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Raises:</p>
<ul class="raise">
<li>
<span class='type'>(<tt>TypeError</tt>)</span>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
551
552
553</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/fork.rb', line 551</span>
<span class='kw'>def</span> <span class='id identifier rubyid_dup'>dup</span> <span class='comment'># :nodoc:
</span> <span class='id identifier rubyid_raise'>raise</span> <span class='const'>TypeError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>can't dup </span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='rbrace'>}</span><span class='tstring_end'>&quot;</span></span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="exception-instance_method">
- (<tt>Object</tt>) <strong>exception</strong>(blocking = true)
</h3><div class="docstring">
<div class="discussion">
<p>The exception that terminated the fork
Requires the :exceptions flag to be set when creating the fork.</p>
</div>
</div>
<div class="tags">
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
343
344
345
346
347
348
349</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/fork.rb', line 343</span>
<span class='kw'>def</span> <span class='id identifier rubyid_exception'>exception</span><span class='lparen'>(</span><span class='id identifier rubyid_blocking'>blocking</span><span class='op'>=</span><span class='kw'>true</span><span class='rparen'>)</span>
<span class='ivar'>@exception</span> <span class='op'>||</span> <span class='kw'>begin</span>
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>FlagNotSpecified</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>You must set the :exceptions flag when forking in order to use this</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_handle_exceptions?'>handle_exceptions?</span>
<span class='id identifier rubyid__wait'>_wait</span><span class='lparen'>(</span><span class='id identifier rubyid_blocking'>blocking</span><span class='rparen'>)</span>
<span class='ivar'>@exception</span>
<span class='kw'>end</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="execute-instance_method">
- (<tt>self</tt>) <strong>execute</strong>
</h3><div class="docstring">
<div class="discussion">
<p>Creates the fork (subprocess) and starts executing it.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>self</tt>)</span>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/fork.rb', line 228</span>
<span class='kw'>def</span> <span class='id identifier rubyid_execute'>execute</span>
<span class='id identifier rubyid_ctrl_read'>ctrl_read</span><span class='comma'>,</span> <span class='id identifier rubyid_ctrl_write'>ctrl_write</span><span class='comma'>,</span> <span class='id identifier rubyid_fork_read'>fork_read</span><span class='comma'>,</span> <span class='id identifier rubyid_parent_write'>parent_write</span><span class='comma'>,</span> <span class='id identifier rubyid_parent_read'>parent_read</span><span class='comma'>,</span> <span class='id identifier rubyid_fork_write'>fork_write</span> <span class='op'>=</span> <span class='kw'>nil</span>
<span class='id identifier rubyid_fork_read'>fork_read</span><span class='comma'>,</span> <span class='id identifier rubyid_parent_write'>parent_write</span> <span class='op'>=</span> <span class='id identifier rubyid_binary_pipe'>binary_pipe</span> <span class='kw'>if</span> <span class='ivar'>@flags</span><span class='lbracket'>[</span><span class='symbol'>:to_fork</span><span class='rbracket'>]</span>
<span class='id identifier rubyid_parent_read'>parent_read</span><span class='comma'>,</span> <span class='id identifier rubyid_fork_write'>fork_write</span> <span class='op'>=</span> <span class='id identifier rubyid_binary_pipe'>binary_pipe</span> <span class='kw'>if</span> <span class='ivar'>@flags</span><span class='lbracket'>[</span><span class='symbol'>:from_fork</span><span class='rbracket'>]</span>
<span class='id identifier rubyid_ctrl_read'>ctrl_read</span><span class='comma'>,</span> <span class='id identifier rubyid_ctrl_write'>ctrl_write</span> <span class='op'>=</span> <span class='id identifier rubyid_binary_pipe'>binary_pipe</span> <span class='kw'>if</span> <span class='ivar'>@flags</span><span class='lbracket'>[</span><span class='symbol'>:ctrl</span><span class='rbracket'>]</span>
<span class='ivar'>@alive</span> <span class='op'>=</span> <span class='kw'>true</span>
<span class='id identifier rubyid_pid'>pid</span> <span class='op'>=</span> <span class='const'>Process</span><span class='period'>.</span><span class='id identifier rubyid_fork'>fork</span> <span class='kw'>do</span>
<span class='ivar'>@parent</span> <span class='op'>=</span> <span class='kw'>false</span>
<span class='id identifier rubyid_parent_write'>parent_write</span><span class='period'>.</span><span class='id identifier rubyid_close'>close</span> <span class='kw'>if</span> <span class='id identifier rubyid_parent_write'>parent_write</span>
<span class='id identifier rubyid_parent_read'>parent_read</span><span class='period'>.</span><span class='id identifier rubyid_close'>close</span> <span class='kw'>if</span> <span class='id identifier rubyid_parent_read'>parent_read</span>
<span class='id identifier rubyid_ctrl_read'>ctrl_read</span><span class='period'>.</span><span class='id identifier rubyid_close'>close</span> <span class='kw'>if</span> <span class='id identifier rubyid_ctrl_read'>ctrl_read</span>
<span class='id identifier rubyid_complete!'>complete!</span><span class='lparen'>(</span><span class='const'>Process</span><span class='period'>.</span><span class='id identifier rubyid_pid'>pid</span><span class='comma'>,</span> <span class='id identifier rubyid_fork_read'>fork_read</span><span class='comma'>,</span> <span class='id identifier rubyid_fork_write'>fork_write</span><span class='comma'>,</span> <span class='id identifier rubyid_ctrl_write'>ctrl_write</span><span class='rparen'>)</span>
<span class='id identifier rubyid_child_process'>child_process</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_fork_write'>fork_write</span><span class='period'>.</span><span class='id identifier rubyid_close'>close</span> <span class='kw'>if</span> <span class='id identifier rubyid_fork_write'>fork_write</span>
<span class='id identifier rubyid_fork_read'>fork_read</span><span class='period'>.</span><span class='id identifier rubyid_close'>close</span> <span class='kw'>if</span> <span class='id identifier rubyid_fork_read'>fork_read</span>
<span class='id identifier rubyid_ctrl_write'>ctrl_write</span><span class='period'>.</span><span class='id identifier rubyid_close'>close</span> <span class='kw'>if</span> <span class='id identifier rubyid_ctrl_write'>ctrl_write</span>
<span class='id identifier rubyid_complete!'>complete!</span><span class='lparen'>(</span><span class='id identifier rubyid_pid'>pid</span><span class='comma'>,</span> <span class='id identifier rubyid_parent_read'>parent_read</span><span class='comma'>,</span> <span class='id identifier rubyid_parent_write'>parent_write</span><span class='comma'>,</span> <span class='id identifier rubyid_ctrl_read'>ctrl_read</span><span class='rparen'>)</span>
<span class='kw'>self</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="exit_status-instance_method">
- (<tt>Object</tt>) <strong>exit_status</strong>(blocking = true)
</h3><div class="docstring">
<div class="discussion">
<p>The exit status of this fork.
See Process::Status#exitstatus</p>
</div>
</div>
<div class="tags">
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
316
317
318
319
320
321
322
323</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/fork.rb', line 316</span>
<span class='kw'>def</span> <span class='id identifier rubyid_exit_status'>exit_status</span><span class='lparen'>(</span><span class='id identifier rubyid_blocking'>blocking</span><span class='op'>=</span><span class='kw'>true</span><span class='rparen'>)</span>
<span class='ivar'>@exit_status</span> <span class='op'>||</span> <span class='kw'>begin</span>
<span class='id identifier rubyid__wait'>_wait</span><span class='lparen'>(</span><span class='id identifier rubyid_blocking'>blocking</span><span class='rparen'>)</span>
<span class='ivar'>@exit_status</span>
<span class='kw'>rescue</span> <span class='const'>NotRunning</span>
<span class='id identifier rubyid_raise'>raise</span> <span class='kw'>if</span> <span class='id identifier rubyid_blocking'>blocking</span> <span class='comment'># calling exit status on a not-yet started fork is an exception, nil otherwise
</span> <span class='kw'>end</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="failure?-instance_method">
- (<tt>Boolean</tt>) <strong>failure?</strong>
</h3><div class="docstring">
<div class="discussion">
<p>Blocks until the fork has exited.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>Boolean</tt>)</span>
&mdash;
<div class='inline'><p>Whether the fork exited with an unsuccessful exit status (status code != 0).</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
337
338
339</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/fork.rb', line 337</span>
<span class='kw'>def</span> <span class='id identifier rubyid_failure?'>failure?</span>
<span class='op'>!</span><span class='id identifier rubyid_success?'>success?</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="fork?-instance_method">
- (<tt>Boolean</tt>) <strong>fork?</strong>
</h3><div class="docstring">
<div class="discussion">
<p>Whether the current code is executed in the fork, as opposed to the parent.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>Boolean</tt>)</span>
&mdash;
<div class='inline'><p>Whether the current code is executed in the fork, as opposed to the parent.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
293
294
295</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/fork.rb', line 293</span>
<span class='kw'>def</span> <span class='id identifier rubyid_fork?'>fork?</span>
<span class='op'>!</span><span class='ivar'>@parent</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="gets-instance_method">
- (<tt>String</tt><sup>?</sup>) <strong>gets</strong>(*args)
</h3><div class="docstring">
<div class="discussion">
<p>In the parent process: read data from the fork.
In the forked process: read data from the parent.
Works just like IO#gets.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>String</tt>, <tt>nil</tt>)</span>
&mdash;
<div class='inline'><p>The data that the forked/parent process has written.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
376
377
378
379
380
381
382</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/fork.rb', line 376</span>
<span class='kw'>def</span> <span class='id identifier rubyid_gets'>gets</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span>
<span class='ivar'>@readable_io</span><span class='period'>.</span><span class='id identifier rubyid_gets'>gets</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span>
<span class='kw'>rescue</span> <span class='const'>NoMethodError</span>
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>NotRunning</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Fork is not running yet, you must invoke #execute first.</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>unless</span> <span class='ivar'>@pid</span>
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>FlagNotSpecified</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>You must set the :to_fork flag when forking in order to use this</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>unless</span> <span class='ivar'>@readable_io</span>
<span class='id identifier rubyid_raise'>raise</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="handle_exceptions?-instance_method">
- (<tt>Boolean</tt>) <strong>handle_exceptions?</strong>
</h3><div class="docstring">
<div class="discussion">
<p>Whether this fork sends the final exception to the parent</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>Boolean</tt>)</span>
&mdash;
<div class='inline'><p>Whether this fork sends the final exception to the parent</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
256
257
258</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/fork.rb', line 256</span>
<span class='kw'>def</span> <span class='id identifier rubyid_handle_exceptions?'>handle_exceptions?</span>
<span class='ivar'>@flags</span><span class='lbracket'>[</span><span class='symbol'>:exceptions</span><span class='rbracket'>]</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="has_ctrl?-instance_method">
- (<tt>Boolean</tt>) <strong>has_ctrl?</strong>
</h3><div class="docstring">
<div class="discussion">
<p>Whether parent and fork use a control-io.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>Boolean</tt>)</span>
&mdash;
<div class='inline'><p>Whether parent and fork use a control-io.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
281
282
283</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/fork.rb', line 281</span>
<span class='kw'>def</span> <span class='id identifier rubyid_has_ctrl?'>has_ctrl?</span>
<span class='ivar'>@flags</span><span class='lbracket'>[</span><span class='symbol'>:ctrl</span><span class='rbracket'>]</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="has_in?-instance_method">
- (<tt>Boolean</tt>) <strong>has_in?</strong>
</h3><div class="docstring">
<div class="discussion">
<p>Whether the other process can write to this process.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>Boolean</tt>)</span>
&mdash;
<div class='inline'><p>Whether the other process can write to this process.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
271
272
273</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/fork.rb', line 271</span>
<span class='kw'>def</span> <span class='id identifier rubyid_has_in?'>has_in?</span>
<span class='ivar'>@flags</span><span class='lbracket'>[</span><span class='id identifier rubyid_parent?'>parent?</span> <span class='op'>?</span> <span class='symbol'>:from_fork</span> <span class='op'>:</span> <span class='symbol'>:to_fork</span><span class='rbracket'>]</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="has_out?-instance_method">
- (<tt>Boolean</tt>) <strong>has_out?</strong>
</h3><div class="docstring">
<div class="discussion">
<p>Whether this process can write to the other process.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>Boolean</tt>)</span>
&mdash;
<div class='inline'><p>Whether this process can write to the other process.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
276
277
278</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/fork.rb', line 276</span>
<span class='kw'>def</span> <span class='id identifier rubyid_has_out?'>has_out?</span>
<span class='ivar'>@flags</span><span class='lbracket'>[</span><span class='id identifier rubyid_parent?'>parent?</span> <span class='op'>?</span> <span class='symbol'>:to_fork</span> <span class='op'>:</span> <span class='symbol'>:from_fork</span><span class='rbracket'>]</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="inspect-instance_method">
- (<tt>Object</tt>) <strong>inspect</strong>
</h3><div class="docstring">
<div class="discussion">
<p>See Object#inspect</p>
</div>
</div>
<div class="tags">
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
563
564
565</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/fork.rb', line 563</span>
<span class='kw'>def</span> <span class='id identifier rubyid_inspect'>inspect</span> <span class='comment'># :nodoc:
</span> <span class='id identifier rubyid_sprintf'>sprintf</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>#&lt;%p pid=%p alive=%p&gt;</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='comma'>,</span> <span class='ivar'>@pid</span><span class='comma'>,</span> <span class='ivar'>@alive</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="kill-instance_method">
- (<tt>Object</tt>) <strong>kill</strong>
</h3><div class="docstring">
<div class="discussion">
<p>Sends the (SIG)HUP signal to this fork.
This is &ldquo;gently asking the process to terminate&rdquo;.
This gives the process a chance to perform some cleanup.
See Fork#kill!, Fork#signal, Process.kill</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Raises:</p>
<ul class="raise">
<li>
<span class='type'>(<tt><span class='object_link'><a href="Fork/NotRunning.html" title="Fork::NotRunning (class)">NotRunning</a></span></tt>)</span>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
520
521
522
523</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/fork.rb', line 520</span>
<span class='kw'>def</span> <span class='id identifier rubyid_kill'>kill</span>
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>NotRunning</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Fork is not running yet, you must invoke #execute first.</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>unless</span> <span class='ivar'>@pid</span>
<span class='const'>Process</span><span class='period'>.</span><span class='id identifier rubyid_kill'>kill</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>HUP</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='ivar'>@pid</span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="kill!-instance_method">
- (<tt>Object</tt>) <strong>kill!</strong>
</h3><div class="docstring">
<div class="discussion">
<p>Sends the (SIG)KILL signal to this fork.
The process will be immediatly terminated and will not have a chance to
do any cleanup.
See Fork#kill, Fork#signal, Process.kill</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Raises:</p>
<ul class="raise">
<li>
<span class='type'>(<tt><span class='object_link'><a href="Fork/NotRunning.html