Sophie

Sophie

distrib > Mageia > 7 > x86_64 > by-pkgid > 641ebb3060c35990cc021d8f7aaf9aca > files > 167

octave-doc-5.1.0-7.1.mga7.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Controlling Subprocesses (GNU Octave (version 5.1.0))</title>

<meta name="description" content="Controlling Subprocesses (GNU Octave (version 5.1.0))">
<meta name="keywords" content="Controlling Subprocesses (GNU Octave (version 5.1.0))">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<link href="index.html#Top" rel="start" title="Top">
<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="System-Utilities.html#System-Utilities" rel="up" title="System Utilities">
<link href="Process-ID-Information.html#Process-ID-Information" rel="next" title="Process ID Information">
<link href="Base64-and-Binary-Data-Transmission.html#Base64-and-Binary-Data-Transmission" rel="prev" title="Base64 and Binary Data Transmission">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smalllisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>
<link rel="stylesheet" type="text/css" href="octave.css">


</head>

<body lang="en">
<a name="Controlling-Subprocesses"></a>
<div class="header">
<p>
Next: <a href="Process-ID-Information.html#Process-ID-Information" accesskey="n" rel="next">Process ID Information</a>, Previous: <a href="Networking-Utilities.html#Networking-Utilities" accesskey="p" rel="prev">Networking Utilities</a>, Up: <a href="System-Utilities.html#System-Utilities" accesskey="u" rel="up">System Utilities</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<a name="Controlling-Subprocesses-1"></a>
<h3 class="section">36.5 Controlling Subprocesses</h3>

<p>Octave includes some high-level commands like <code>system</code> and
<code>popen</code> for starting subprocesses.  If you want to run another
program to perform some task and then look at its output, you will
probably want to use these functions.
</p>
<p>Octave also provides several very low-level Unix-like functions which
can also be used for starting subprocesses, but you should probably only
use them if you can&rsquo;t find any way to do what you need with the
higher-level functions.
</p>
<a name="XREFsystem"></a><dl>
<dt><a name="index-system"></a><em></em> <strong>system</strong> <em>(&quot;<var>string</var>&quot;)</em></dt>
<dt><a name="index-system-1"></a><em></em> <strong>system</strong> <em>(&quot;<var>string</var>&quot;, <var>return_output</var>)</em></dt>
<dt><a name="index-system-2"></a><em></em> <strong>system</strong> <em>(&quot;<var>string</var>&quot;, <var>return_output</var>, <var>type</var>)</em></dt>
<dt><a name="index-system-3"></a><em>[<var>status</var>, <var>output</var>] =</em> <strong>system</strong> <em>(&hellip;)</em></dt>
<dd><p>Execute a shell command specified by <var>string</var>.
</p>
<p>If the optional argument <var>type</var> is <code>&quot;async&quot;</code>, the process is
started in the background and the process ID of the child process is
returned immediately.  Otherwise, the child process is started and Octave
waits until it exits.  If the <var>type</var> argument is omitted, it defaults to
the value <code>&quot;sync&quot;</code>.
</p>
<p>If <var>system</var> is called with one or more output arguments, or if the
optional argument <var>return_output</var> is true and the subprocess is started
synchronously, then the output from the command is returned as a variable.
Otherwise, if the subprocess is executed synchronously, its output is sent
to the standard output.  To send the output of a command executed with
<code>system</code> through the pager, use a command like
</p>
<div class="example">
<pre class="example">[~, text] = system (&quot;cmd&quot;);
more on;
disp (text);
</pre></div>

<p>or
</p>
<div class="example">
<pre class="example">more on;
printf (&quot;%s\n&quot;, nthargout (2, &quot;system&quot;, &quot;cmd&quot;));
</pre></div>

<p>The <code>system</code> function can return two values.  The first is the
exit status of the command and the second is any output from the
command that was written to the standard output stream.  For example,
</p>
<div class="example">
<pre class="example">[status, output] = system (&quot;echo foo &amp; exit 2&quot;);
</pre></div>

<p>will set the variable <var>output</var> to the string &lsquo;<samp>foo</samp>&rsquo;, and the
variable <var>status</var> to the integer &lsquo;<samp>2</samp>&rsquo;.
</p>
<p>For commands run asynchronously, <var>status</var> is the process id of the
command shell that is started to run the command.
</p>
<p>The shell used for executing commands varies with operating system and is
typically <samp>/bin/sh</samp> for UNIX systems and <samp>cmd.exe</samp> for
Windows
systems.
</p>
<p><strong>See also:</strong> <a href="#XREFunix">unix</a>, <a href="#XREFdos">dos</a>.
</p></dd></dl>


<a name="XREFunix"></a><dl>
<dt><a name="index-unix"></a><em></em> <strong>unix</strong> <em>(&quot;<var>command</var>&quot;)</em></dt>
<dt><a name="index-unix-1"></a><em><var>status</var> =</em> <strong>unix</strong> <em>(&quot;<var>command</var>&quot;)</em></dt>
<dt><a name="index-unix-2"></a><em>[<var>status</var>, <var>text</var>] =</em> <strong>unix</strong> <em>(&quot;<var>command</var>&quot;)</em></dt>
<dt><a name="index-unix-3"></a><em>[&hellip;] =</em> <strong>unix</strong> <em>(&quot;<var>command</var>&quot;, &quot;-echo&quot;)</em></dt>
<dd><p>Execute a system command if running under a Unix-like operating system,
otherwise do nothing.
</p>
<p>Octave waits for the external command to finish before returning the exit
status of the program in <var>status</var> and any output in <var>text</var>.
</p>
<p>When called with no output argument, or the <code>&quot;-echo&quot;</code> argument is
given, then <var>text</var> is also sent to standard output.
</p>
<p><strong>See also:</strong> <a href="#XREFdos">dos</a>, <a href="#XREFsystem">system</a>, <a href="System-Information.html#XREFisunix">isunix</a>, <a href="System-Information.html#XREFismac">ismac</a>, <a href="System-Information.html#XREFispc">ispc</a>.
</p></dd></dl>


<a name="XREFdos"></a><dl>
<dt><a name="index-dos"></a><em></em> <strong>dos</strong> <em>(&quot;<var>command</var>&quot;)</em></dt>
<dt><a name="index-dos-1"></a><em><var>status</var> =</em> <strong>dos</strong> <em>(&quot;<var>command</var>&quot;)</em></dt>
<dt><a name="index-dos-2"></a><em>[<var>status</var>, <var>text</var>] =</em> <strong>dos</strong> <em>(&quot;<var>command&quot;</var>)</em></dt>
<dt><a name="index-dos-3"></a><em>[&hellip;] =</em> <strong>dos</strong> <em>(&quot;<var>command</var>&quot;, &quot;-echo&quot;)</em></dt>
<dd><p>Execute a system command if running under a Windows-like operating system,
otherwise do nothing.
</p>
<p>Octave waits for the external command to finish before returning the exit
status of the program in <var>status</var> and any output in <var>text</var>.
</p>
<p>When called with no output argument, or the <code>&quot;-echo&quot;</code> argument is
given, then <var>text</var> is also sent to standard output.
</p>
<p><strong>See also:</strong> <a href="#XREFunix">unix</a>, <a href="#XREFsystem">system</a>, <a href="System-Information.html#XREFisunix">isunix</a>, <a href="System-Information.html#XREFismac">ismac</a>, <a href="System-Information.html#XREFispc">ispc</a>.
</p></dd></dl>


<a name="XREFopen"></a><dl>
<dt><a name="index-open"></a><em></em> <strong>open</strong> <em><var>file</var></em></dt>
<dt><a name="index-open-1"></a><em><var>output</var> =</em> <strong>open</strong> <em>(<var>file</var>)</em></dt>
<dd><p>Open the file <var>file</var> in Octave or in an external application based on
the file type as determined by the filename extension.
</p>
<p>By default, recognized file types are
</p>
<dl compact="compact">
<dt><code>.m</code></dt>
<dd><p>Open file in the editor.  No <var>output</var> value is returned.
</p>
</dd>
<dt><code>.mat</code></dt>
<dt><code>octave-workspace</code></dt>
<dd><p>Open the data file with <code>load</code>.  If no return value <var>output</var>
is requested, variables are loaded in the base workspace.  Otherwise
<var>output</var> will be a structure containing loaded data.
See <a href="Simple-File-I_002fO.html#XREFload">load function</a>.
</p>
</dd>
<dt><code>.ofig</code></dt>
<dd><p>Open the figure with hgload.  See <a href="Printing-and-Saving-Plots.html#XREFhgload">hgload function</a>.
</p>
</dd>
<dt><code>.fig, .ofig</code></dt>
<dd><p>Load the figure
</p>
</dd>
<dt><code>.exe</code></dt>
<dd><p>Execute the program (on Windows systems only).  No <var>output</var> value
is returned.
</p></dd>
</dl>

<p>Custom file extensions may also be handled if a function <code>openxxx</code>,
where <code>xxx</code> is the extension, is found in the load path.  The function
must accept the file name as input.  For example, in order to load
<code>&quot;.dat&quot;</code> data files in the base workspace, as is done by
default for <code>&quot;.mat&quot;</code> files, one may define
<code>&quot;opendat.m&quot;</code> with the following contents:
</p>
<div class="example">
<pre class="example">function retval = opendat (fname)
  evalin (&quot;base&quot;, sprintf (&quot;load ('%s');&quot;, fname));
endfunction
</pre></div>

<p>Other file types are opened in the appropriate external application.
</p></dd></dl>


<a name="XREFperl"></a><dl>
<dt><a name="index-perl"></a><em><var>output</var> =</em> <strong>perl</strong> <em>(<var>scriptfile</var>)</em></dt>
<dt><a name="index-perl-1"></a><em><var>output</var> =</em> <strong>perl</strong> <em>(<var>scriptfile</var>, <var>argument1</var>, <var>argument2</var>, &hellip;)</em></dt>
<dt><a name="index-perl-2"></a><em>[<var>output</var>, <var>status</var>] =</em> <strong>perl</strong> <em>(&hellip;)</em></dt>
<dd><p>Invoke Perl script <var>scriptfile</var>, possibly with a list of command line
arguments.
</p>
<p>Return output in <var>output</var> and optional status in <var>status</var>.  If
<var>scriptfile</var> is not an absolute filename it is searched for in the
current directory and then in the Octave loadpath.
</p>
<p><strong>See also:</strong> <a href="#XREFsystem">system</a>, <a href="#XREFpython">python</a>.
</p></dd></dl>


<a name="XREFpython"></a><dl>
<dt><a name="index-python"></a><em><var>output</var> =</em> <strong>python</strong> <em>(<var>scriptfile</var>)</em></dt>
<dt><a name="index-python-1"></a><em><var>output</var> =</em> <strong>python</strong> <em>(<var>scriptfile</var>, <var>argument1</var>, <var>argument2</var>, &hellip;)</em></dt>
<dt><a name="index-python-2"></a><em>[<var>output</var>, <var>status</var>] =</em> <strong>python</strong> <em>(&hellip;)</em></dt>
<dd><p>Invoke Python script <var>scriptfile</var>, possibly with a list of command line
arguments.
</p>
<p>Return output in <var>output</var> and optional status in <var>status</var>.  If
<var>scriptfile</var> is not an absolute filename it is searched for in the
current directory and then in the Octave loadpath.
</p>
<p><strong>See also:</strong> <a href="#XREFsystem">system</a>, <a href="#XREFperl">perl</a>.
</p></dd></dl>


<a name="XREFpopen"></a><dl>
<dt><a name="index-popen"></a><em><var>fid</var> =</em> <strong>popen</strong> <em>(<var>command</var>, <var>mode</var>)</em></dt>
<dd><p>Start a process and create a pipe.
</p>
<p>The name of the command to run is given by <var>command</var>.  The argument
<var>mode</var> may be
</p>
<dl compact="compact">
<dt><code>&quot;r&quot;</code></dt>
<dd><p>The pipe will be connected to the standard output of the process, and
open for reading.
</p>
</dd>
<dt><code>&quot;w&quot;</code></dt>
<dd><p>The pipe will be connected to the standard input of the process, and
open for writing.
</p></dd>
</dl>

<p>The file identifier corresponding to the input or output stream of the
process is returned in <var>fid</var>.
</p>
<p>For example:
</p>
<div class="example">
<pre class="example">fid = popen (&quot;ls -ltr / | tail -3&quot;, &quot;r&quot;);
while (ischar (s = fgets (fid)))
  fputs (stdout, s);
endwhile

   -| drwxr-xr-x  33 root  root  3072 Feb 15 13:28 etc
   -| drwxr-xr-x   3 root  root  1024 Feb 15 13:28 lib
   -| drwxrwxrwt  15 root  root  2048 Feb 17 14:53 tmp
</pre></div>

<p><strong>See also:</strong> <a href="#XREFpopen2">popen2</a>.
</p></dd></dl>


<a name="XREFpclose"></a><dl>
<dt><a name="index-pclose"></a><em></em> <strong>pclose</strong> <em>(<var>fid</var>)</em></dt>
<dd><p>Close a file identifier that was opened by <code>popen</code>.
</p>
<p>The function <code>fclose</code> may also be used for the same purpose.
</p>
<p><strong>See also:</strong> <a href="Opening-and-Closing-Files.html#XREFfclose">fclose</a>, <a href="#XREFpopen">popen</a>.
</p></dd></dl>


<a name="XREFpopen2"></a><dl>
<dt><a name="index-popen2"></a><em>[<var>in</var>, <var>out</var>, <var>pid</var>] =</em> <strong>popen2</strong> <em>(<var>command</var>, <var>args</var>)</em></dt>
<dd><p>Start a subprocess with two-way communication.
</p>
<p>The name of the process is given by <var>command</var>, and <var>args</var> is an
array or cell array of strings containing options for the command.
</p>
<p>The file identifiers for the input and output streams of the subprocess are
returned in <var>in</var> and <var>out</var>.  If execution of the command is
successful, <var>pid</var> contains the process ID of the subprocess.  Otherwise,
<var>pid</var> is -1.
</p>
<p>For example:
</p>
<div class="example">
<pre class="example">[in, out, pid] = popen2 (&quot;sort&quot;, &quot;-r&quot;);
fputs (in, &quot;these\nare\nsome\nstrings\n&quot;);
fclose (in);
EAGAIN = errno (&quot;EAGAIN&quot;);
done = false;
do
  s = fgets (out);
  if (ischar (s))
    fputs (stdout, s);
  elseif (errno () == EAGAIN)
    pause (0.1);
    fclear (out);
  else
    done = true;
  endif
until (done)
fclose (out);
waitpid (pid);

   -| these
   -| strings
   -| some
   -| are
</pre></div>

<p>Note that <code>popen2</code>, unlike <code>popen</code>, will not &quot;reap&quot;
the child process.  If you don&rsquo;t use <code>waitpid</code> to check the child&rsquo;s
exit status, it will linger until Octave exits.
</p>
<p><strong>See also:</strong> <a href="#XREFpopen">popen</a>, <a href="#XREFwaitpid">waitpid</a>.
</p></dd></dl>


<a name="XREFEXEC_005fPATH"></a><dl>
<dt><a name="index-EXEC_005fPATH"></a><em><var>val</var> =</em> <strong>EXEC_PATH</strong> <em>()</em></dt>
<dt><a name="index-EXEC_005fPATH-1"></a><em><var>old_val</var> =</em> <strong>EXEC_PATH</strong> <em>(<var>new_val</var>)</em></dt>
<dt><a name="index-EXEC_005fPATH-2"></a><em></em> <strong>EXEC_PATH</strong> <em>(<var>new_val</var>, &quot;local&quot;)</em></dt>
<dd><p>Query or set the internal variable that specifies a colon separated
list of directories to append to the shell PATH when executing external
programs.
</p>
<p>The initial value of is taken from the environment variable
<code><span class="nolinebreak">OCTAVE_EXEC_PATH</span></code><!-- /@w -->, but that value can be overridden by the command
line argument <samp>--exec-path PATH</samp>.
</p>
<p>When called from inside a function with the <code>&quot;local&quot;</code> option, the
variable is changed locally for the function and any subroutines it calls.
The original variable value is restored when exiting the function.
</p>

<p><strong>See also:</strong> <a href="Loading-and-Saving-Images.html#XREFIMAGE_005fPATH">IMAGE_PATH</a>, <a href="System-Information.html#XREFOCTAVE_005fHOME">OCTAVE_HOME</a>, <a href="System-Information.html#XREFOCTAVE_005fEXEC_005fHOME">OCTAVE_EXEC_HOME</a>.
</p></dd></dl>


<p>In most cases, the following functions simply decode their arguments and
make the corresponding Unix system calls.  For a complete example of how
they can be used, look at the definition of the function <code>popen2</code>.
</p>
<a name="XREFfork"></a><dl>
<dt><a name="index-fork"></a><em>[<var>pid</var>, <var>msg</var>] =</em> <strong>fork</strong> <em>()</em></dt>
<dd><p>Create a copy of the current process.
</p>
<p>Fork can return one of the following values:
</p>
<dl compact="compact">
<dt>&gt; 0</dt>
<dd><p>You are in the parent process.  The value returned from <code>fork</code> is the
process id of the child process.  You should probably arrange to wait for
any child processes to exit.
</p>
</dd>
<dt>0</dt>
<dd><p>You are in the child process.  You can call <code>exec</code> to start another
process.  If that fails, you should probably call <code>exit</code>.
</p>
</dd>
<dt>&lt; 0</dt>
<dd><p>The call to <code>fork</code> failed for some reason.  You must take evasive
action.  A system dependent error message will be waiting in <var>msg</var>.
</p></dd>
</dl>
</dd></dl>


<a name="XREFexec"></a><dl>
<dt><a name="index-exec"></a><em>[<var>err</var>, <var>msg</var>] =</em> <strong>exec</strong> <em>(<var>file</var>, <var>args</var>)</em></dt>
<dd><p>Replace current process with a new process.
</p>
<p>Calling <code>exec</code> without first calling <code>fork</code> will terminate your
current Octave process and replace it with the program named by <var>file</var>.
For example,
</p>
<div class="example">
<pre class="example">exec (&quot;ls&quot;, &quot;-l&quot;)
</pre></div>

<p>will run <code>ls</code> and return you to your shell prompt.
</p>
<p>If successful, <code>exec</code> does not return.  If <code>exec</code> does return,
<var>err</var> will be nonzero, and <var>msg</var> will contain a system-dependent
error message.
</p></dd></dl>


<a name="XREFpipe"></a><dl>
<dt><a name="index-pipe"></a><em>[<var>read_fd</var>, <var>write_fd</var>, <var>err</var>, <var>msg</var>] =</em> <strong>pipe</strong> <em>()</em></dt>
<dd><p>Create a pipe and return the reading and writing ends of the pipe into
<var>read_fd</var> and <var>write_fd</var> respectively.
</p>
<p>If successful, <var>err</var> is 0 and <var>msg</var> is an empty string.
Otherwise, <var>err</var> is nonzero and <var>msg</var> contains a system-dependent
error message.
</p>
<p><strong>See also:</strong> <a href="Filesystem-Utilities.html#XREFmkfifo">mkfifo</a>.
</p></dd></dl>


<a name="XREFdup2"></a><dl>
<dt><a name="index-dup2"></a><em>[<var>fid</var>, <var>msg</var>] =</em> <strong>dup2</strong> <em>(<var>old</var>, <var>new</var>)</em></dt>
<dd><p>Duplicate a file descriptor.
</p>
<p>If successful, <var>fid</var> is greater than zero and contains the new file ID.
Otherwise, <var>fid</var> is negative and <var>msg</var> contains a system-dependent
error message.
</p>
<p><strong>See also:</strong> <a href="Opening-and-Closing-Files.html#XREFfopen">fopen</a>, <a href="Opening-and-Closing-Files.html#XREFfclose">fclose</a>, <a href="#XREFfcntl">fcntl</a>.
</p></dd></dl>


<a name="XREFwaitpid"></a><dl>
<dt><a name="index-waitpid"></a><em>[<var>pid</var>, <var>status</var>, <var>msg</var>] =</em> <strong>waitpid</strong> <em>(<var>pid</var>, <var>options</var>)</em></dt>
<dd><p>Wait for process <var>pid</var> to terminate.
</p>
<p>The <var>pid</var> argument can be:
</p>
<dl compact="compact">
<dt>-1</dt>
<dd><p>Wait for any child process.
</p>
</dd>
<dt>0</dt>
<dd><p>Wait for any child process whose process group ID is equal to that of the
Octave interpreter process.
</p>
</dd>
<dt>&gt; 0</dt>
<dd><p>Wait for termination of the child process with ID <var>pid</var>.
</p></dd>
</dl>

<p>The <var>options</var> argument can be a bitwise OR of zero or more of the
following constants:
</p>
<dl compact="compact">
<dt><code>0</code></dt>
<dd><p>Wait until signal is received or a child process exits (this is the default
if the <var>options</var> argument is missing).
</p>
</dd>
<dt><code>WNOHANG</code></dt>
<dd><p>Do not hang if status is not immediately available.
</p>
</dd>
<dt><code>WUNTRACED</code></dt>
<dd><p>Report the status of any child processes that are stopped, and whose status
has not yet been reported since they stopped.
</p>
</dd>
<dt><code>WCONTINUE</code></dt>
<dd><p>Return if a stopped child has been resumed by delivery of <code>SIGCONT</code>.
This value may not be meaningful on all systems.
</p></dd>
</dl>

<p>If the returned value of <var>pid</var> is greater than 0, it is the process ID
of the child process that exited.  If an error occurs, <var>pid</var> will be
less than zero and <var>msg</var> will contain a system-dependent error message.
The value of <var>status</var> contains additional system-dependent information
about the subprocess that exited.
</p>
<p><strong>See also:</strong> <a href="#XREFWCONTINUE">WCONTINUE</a>, <a href="#XREFWCOREDUMP">WCOREDUMP</a>, <a href="#XREFWEXITSTATUS">WEXITSTATUS</a>, <a href="#XREFWIFCONTINUED">WIFCONTINUED</a>, <a href="#XREFWIFSIGNALED">WIFSIGNALED</a>, <a href="#XREFWIFSTOPPED">WIFSTOPPED</a>, <a href="#XREFWNOHANG">WNOHANG</a>, <a href="#XREFWSTOPSIG">WSTOPSIG</a>, <a href="#XREFWTERMSIG">WTERMSIG</a>, <a href="#XREFWUNTRACED">WUNTRACED</a>.
</p></dd></dl>


<a name="XREFWCONTINUE"></a><dl>
<dt><a name="index-WCONTINUE"></a><em></em> <strong>WCONTINUE</strong> <em>()</em></dt>
<dd><p>Return the numerical value of the <code>WCONTINUE</code> macro.
</p>
<p><code>WCONTINUE</code> is the option argument that may be passed to
<code>waitpid</code> to indicate that it should also return if a stopped child
has been resumed by delivery of a <code>SIGCONT</code> signal.
</p>
<p><strong>See also:</strong> <a href="#XREFwaitpid">waitpid</a>, <a href="#XREFWNOHANG">WNOHANG</a>, <a href="#XREFWUNTRACED">WUNTRACED</a>.
</p></dd></dl>


<a name="XREFWCOREDUMP"></a><dl>
<dt><a name="index-WCOREDUMP"></a><em></em> <strong>WCOREDUMP</strong> <em>(<var>status</var>)</em></dt>
<dd><p>Given <var>status</var> from a call to <code>waitpid</code>, return
true if the child produced a core dump.
</p>
<p>This function should only be employed if <code>WIFSIGNALED</code> returned true.
The macro used to implement this function is not specified in POSIX.1-2001
and is not available on some Unix implementations (e.g., AIX, SunOS).
</p>
<p><strong>See also:</strong> <a href="#XREFwaitpid">waitpid</a>, <a href="#XREFWIFEXITED">WIFEXITED</a>, <a href="#XREFWEXITSTATUS">WEXITSTATUS</a>, <a href="#XREFWIFSIGNALED">WIFSIGNALED</a>, <a href="#XREFWTERMSIG">WTERMSIG</a>, <a href="#XREFWIFSTOPPED">WIFSTOPPED</a>, <a href="#XREFWSTOPSIG">WSTOPSIG</a>, <a href="#XREFWIFCONTINUED">WIFCONTINUED</a>.
</p></dd></dl>


<a name="XREFWEXITSTATUS"></a><dl>
<dt><a name="index-WEXITSTATUS"></a><em></em> <strong>WEXITSTATUS</strong> <em>(<var>status</var>)</em></dt>
<dd><p>Given <var>status</var> from a call to <code>waitpid</code>, return
the exit status of the child.
</p>
<p>This function should only be employed if <code>WIFEXITED</code> returned true.
</p>
<p><strong>See also:</strong> <a href="#XREFwaitpid">waitpid</a>, <a href="#XREFWIFEXITED">WIFEXITED</a>, <a href="#XREFWIFSIGNALED">WIFSIGNALED</a>, <a href="#XREFWTERMSIG">WTERMSIG</a>, <a href="#XREFWCOREDUMP">WCOREDUMP</a>, <a href="#XREFWIFSTOPPED">WIFSTOPPED</a>, <a href="#XREFWSTOPSIG">WSTOPSIG</a>, <a href="#XREFWIFCONTINUED">WIFCONTINUED</a>.
</p></dd></dl>


<a name="XREFWIFCONTINUED"></a><dl>
<dt><a name="index-WIFCONTINUED"></a><em></em> <strong>WIFCONTINUED</strong> <em>(<var>status</var>)</em></dt>
<dd><p>Given <var>status</var> from a call to <code>waitpid</code>, return
true if the child process was resumed by delivery of <code>SIGCONT</code>.
</p>
<p><strong>See also:</strong> <a href="#XREFwaitpid">waitpid</a>, <a href="#XREFWIFEXITED">WIFEXITED</a>, <a href="#XREFWEXITSTATUS">WEXITSTATUS</a>, <a href="#XREFWIFSIGNALED">WIFSIGNALED</a>, <a href="#XREFWTERMSIG">WTERMSIG</a>, <a href="#XREFWCOREDUMP">WCOREDUMP</a>, <a href="#XREFWIFSTOPPED">WIFSTOPPED</a>, <a href="#XREFWSTOPSIG">WSTOPSIG</a>.
</p></dd></dl>


<a name="XREFWIFSIGNALED"></a><dl>
<dt><a name="index-WIFSIGNALED"></a><em></em> <strong>WIFSIGNALED</strong> <em>(<var>status</var>)</em></dt>
<dd><p>Given <var>status</var> from a call to <code>waitpid</code>, return
true if the child process was terminated by a signal.
</p>
<p><strong>See also:</strong> <a href="#XREFwaitpid">waitpid</a>, <a href="#XREFWIFEXITED">WIFEXITED</a>, <a href="#XREFWEXITSTATUS">WEXITSTATUS</a>, <a href="#XREFWTERMSIG">WTERMSIG</a>, <a href="#XREFWCOREDUMP">WCOREDUMP</a>, <a href="#XREFWIFSTOPPED">WIFSTOPPED</a>, <a href="#XREFWSTOPSIG">WSTOPSIG</a>, <a href="#XREFWIFCONTINUED">WIFCONTINUED</a>.
</p></dd></dl>


<a name="XREFWIFSTOPPED"></a><dl>
<dt><a name="index-WIFSTOPPED"></a><em></em> <strong>WIFSTOPPED</strong> <em>(<var>status</var>)</em></dt>
<dd><p>Given <var>status</var> from a call to <code>waitpid</code>, return
true if the child process was stopped by delivery of a signal.
</p>
<p>This is only possible if the call was done using <code>WUNTRACED</code> or when
the child is being traced (see ptrace(2)).
</p>
<p><strong>See also:</strong> <a href="#XREFwaitpid">waitpid</a>, <a href="#XREFWIFEXITED">WIFEXITED</a>, <a href="#XREFWEXITSTATUS">WEXITSTATUS</a>, <a href="#XREFWIFSIGNALED">WIFSIGNALED</a>, <a href="#XREFWTERMSIG">WTERMSIG</a>, <a href="#XREFWCOREDUMP">WCOREDUMP</a>, <a href="#XREFWSTOPSIG">WSTOPSIG</a>, <a href="#XREFWIFCONTINUED">WIFCONTINUED</a>.
</p></dd></dl>


<a name="XREFWIFEXITED"></a><dl>
<dt><a name="index-WIFEXITED"></a><em></em> <strong>WIFEXITED</strong> <em>(<var>status</var>)</em></dt>
<dd><p>Given <var>status</var> from a call to <code>waitpid</code>, return
true if the child terminated normally.
</p>
<p><strong>See also:</strong> <a href="#XREFwaitpid">waitpid</a>, <a href="#XREFWEXITSTATUS">WEXITSTATUS</a>, <a href="#XREFWIFSIGNALED">WIFSIGNALED</a>, <a href="#XREFWTERMSIG">WTERMSIG</a>, <a href="#XREFWCOREDUMP">WCOREDUMP</a>, <a href="#XREFWIFSTOPPED">WIFSTOPPED</a>, <a href="#XREFWSTOPSIG">WSTOPSIG</a>, <a href="#XREFWIFCONTINUED">WIFCONTINUED</a>.
</p></dd></dl>


<a name="XREFWNOHANG"></a><dl>
<dt><a name="index-WNOHANG"></a><em></em> <strong>WNOHANG</strong> <em>()</em></dt>
<dd><p>Return the numerical value of the <code>WNOHANG</code> macro.
</p>
<p><code>WNOHANG</code> is the option argument that may be passed to
<code>waitpid</code> to indicate that it should return its status immediately
instead of waiting for a process to exit.
</p>
<p><strong>See also:</strong> <a href="#XREFwaitpid">waitpid</a>, <a href="#XREFWUNTRACED">WUNTRACED</a>, <a href="#XREFWCONTINUE">WCONTINUE</a>.
</p></dd></dl>


<a name="XREFWSTOPSIG"></a><dl>
<dt><a name="index-WSTOPSIG"></a><em></em> <strong>WSTOPSIG</strong> <em>(<var>status</var>)</em></dt>
<dd><p>Given <var>status</var> from a call to <code>waitpid</code>, return
the number of the signal which caused the child to stop.
</p>
<p>This function should only be employed if <code>WIFSTOPPED</code> returned true.
</p>
<p><strong>See also:</strong> <a href="#XREFwaitpid">waitpid</a>, <a href="#XREFWIFEXITED">WIFEXITED</a>, <a href="#XREFWEXITSTATUS">WEXITSTATUS</a>, <a href="#XREFWIFSIGNALED">WIFSIGNALED</a>, <a href="#XREFWTERMSIG">WTERMSIG</a>, <a href="#XREFWCOREDUMP">WCOREDUMP</a>, <a href="#XREFWIFSTOPPED">WIFSTOPPED</a>, <a href="#XREFWIFCONTINUED">WIFCONTINUED</a>.
</p></dd></dl>


<a name="XREFWTERMSIG"></a><dl>
<dt><a name="index-WTERMSIG"></a><em></em> <strong>WTERMSIG</strong> <em>(<var>status</var>)</em></dt>
<dd><p>Given <var>status</var> from a call to <code>waitpid</code>, return
the number of the signal that caused the child process to terminate.
</p>
<p>This function should only be employed if <code>WIFSIGNALED</code> returned true.
</p>
<p><strong>See also:</strong> <a href="#XREFwaitpid">waitpid</a>, <a href="#XREFWIFEXITED">WIFEXITED</a>, <a href="#XREFWEXITSTATUS">WEXITSTATUS</a>, <a href="#XREFWIFSIGNALED">WIFSIGNALED</a>, <a href="#XREFWCOREDUMP">WCOREDUMP</a>, <a href="#XREFWIFSTOPPED">WIFSTOPPED</a>, <a href="#XREFWSTOPSIG">WSTOPSIG</a>, <a href="#XREFWIFCONTINUED">WIFCONTINUED</a>.
</p></dd></dl>


<a name="XREFWUNTRACED"></a><dl>
<dt><a name="index-WUNTRACED"></a><em></em> <strong>WUNTRACED</strong> <em>()</em></dt>
<dd><p>Return the numerical value of the <code>WUNTRACED</code> macro.
</p>
<p><code>WUNTRACED</code> is the option argument that may be passed to
<code>waitpid</code> to indicate that it should also return if the child
process has stopped but is not traced via the <code>ptrace</code> system call
</p>
<p><strong>See also:</strong> <a href="#XREFwaitpid">waitpid</a>, <a href="#XREFWNOHANG">WNOHANG</a>, <a href="#XREFWCONTINUE">WCONTINUE</a>.
</p></dd></dl>


<a name="XREFfcntl"></a><dl>
<dt><a name="index-fcntl"></a><em>[<var>err</var>, <var>msg</var>] =</em> <strong>fcntl</strong> <em>(<var>fid</var>, <var>request</var>, <var>arg</var>)</em></dt>
<dd><p>Change the properties of the open file <var>fid</var>.
</p>
<p>The following values may be passed as <var>request</var>:
</p>
<dl compact="compact">
<dt><code>F_DUPFD</code>
<a name="index-F_005fDUPFD"></a>
</dt>
<dd><p>Return a duplicate file descriptor.
</p>
</dd>
<dt><code>F_GETFD</code>
<a name="index-F_005fGETFD"></a>
</dt>
<dd><p>Return the file descriptor flags for <var>fid</var>.
</p>
</dd>
<dt><code>F_SETFD</code>
<a name="index-F_005fSETFD"></a>
</dt>
<dd><p>Set the file descriptor flags for <var>fid</var>.
</p>
</dd>
<dt><code>F_GETFL</code>
<a name="index-F_005fGETFL"></a>
</dt>
<dd><p>Return the file status flags for <var>fid</var>.  The following codes may be
returned (some of the flags may be undefined on some systems).
</p>
<dl compact="compact">
<dt><code>O_RDONLY</code>
<a name="index-O_005fRDONLY"></a>
</dt>
<dd><p>Open for reading only.
</p>
</dd>
<dt><code>O_WRONLY</code>
<a name="index-O_005fWRONLY"></a>
</dt>
<dd><p>Open for writing only.
</p>
</dd>
<dt><code>O_RDWR</code>
<a name="index-O_005fRDWR"></a>
</dt>
<dd><p>Open for reading and writing.
</p>
</dd>
<dt><code>O_APPEND</code>
<a name="index-O_005fAPPEND"></a>
</dt>
<dd><p>Append on each write.
</p>
</dd>
<dt><code>O_CREAT</code>
<a name="index-O_005fCREAT"></a>
</dt>
<dd><p>Create the file if it does not exist.
</p>
</dd>
<dt><code>O_NONBLOCK</code>
<a name="index-O_005fNONBLOCK"></a>
</dt>
<dd><p>Non-blocking mode.
</p>
</dd>
<dt><code>O_SYNC</code>
<a name="index-O_005fSYNC"></a>
</dt>
<dd><p>Wait for writes to complete.
</p>
</dd>
<dt><code>O_ASYNC</code>
<a name="index-O_005fASYNC"></a>
</dt>
<dd><p>Asynchronous I/O.
</p></dd>
</dl>

</dd>
<dt><code>F_SETFL</code>
<a name="index-F_005fSETFL"></a>
</dt>
<dd><p>Set the file status flags for <var>fid</var> to the value specified by <var>arg</var>.
 The only flags that can be changed are <code><span class="nolinebreak">O_APPEND</span></code><!-- /@w --> and
<code><span class="nolinebreak">O_NONBLOCK</span></code><!-- /@w -->.
</p></dd>
</dl>

<p>If successful, <var>err</var> is 0 and <var>msg</var> is an empty string.  Otherwise,
<var>err</var> is nonzero and <var>msg</var> contains a system-dependent error
message.
</p>
<p><strong>See also:</strong> <a href="Opening-and-Closing-Files.html#XREFfopen">fopen</a>, <a href="#XREFdup2">dup2</a>.
</p></dd></dl>


<a name="XREFkill"></a><dl>
<dt><a name="index-kill"></a><em>[<var>err</var>, <var>msg</var>] =</em> <strong>kill</strong> <em>(<var>pid</var>, <var>sig</var>)</em></dt>
<dd><p>Send signal <var>sig</var> to process <var>pid</var>.
</p>
<p>If <var>pid</var> is positive, then signal <var>sig</var> is sent to <var>pid</var>.
</p>
<p>If <var>pid</var> is 0, then signal <var>sig</var> is sent to every process
in the process group of the current process.
</p>
<p>If <var>pid</var> is -1, then signal <var>sig</var> is sent to every process
except process 1.
</p>
<p>If <var>pid</var> is less than -1, then signal <var>sig</var> is sent to every
process in the process group <var>-pid</var>.
</p>
<p>If <var>sig</var> is 0, then no signal is sent, but error checking is still
performed.
</p>
<p>Return 0 if successful, otherwise return -1.
</p></dd></dl>


<a name="XREFSIG"></a><dl>
<dt><a name="index-SIG"></a><em></em> <strong>SIG</strong> <em>()</em></dt>
<dd><p>Return a structure containing Unix signal names and their defined values.
</p></dd></dl>


<hr>
<div class="header">
<p>
Next: <a href="Process-ID-Information.html#Process-ID-Information" accesskey="n" rel="next">Process ID Information</a>, Previous: <a href="Networking-Utilities.html#Networking-Utilities" accesskey="p" rel="prev">Networking Utilities</a>, Up: <a href="System-Utilities.html#System-Utilities" accesskey="u" rel="up">System Utilities</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>