1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 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 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807
|
<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Controlling Subprocesses (GNU Octave (version 10.3.0))</title>
<meta name="description" content="Controlling Subprocesses (GNU Octave (version 10.3.0))">
<meta name="keywords" content="Controlling Subprocesses (GNU Octave (version 10.3.0))">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link href="index.html" rel="start" title="Top">
<link href="Concept-Index.html" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="System-Utilities.html" rel="up" title="System Utilities">
<link href="Process-ID-Information.html" rel="next" title="Process ID Information">
<link href="Networking-Utilities.html" rel="prev" title="Networking Utilities">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.example {margin-left: 3.2em}
span:hover a.copiable-link {visibility: visible}
strong.def-name {font-family: monospace; font-weight: bold; font-size: larger}
-->
</style>
<link rel="stylesheet" type="text/css" href="octave.css">
</head>
<body lang="en">
<div class="section-level-extent" id="Controlling-Subprocesses">
<div class="nav-panel">
<p>
Next: <a href="Process-ID-Information.html" accesskey="n" rel="next">Process, Group, and User IDs</a>, Previous: <a href="Networking-Utilities.html" accesskey="p" rel="prev">Networking Utilities</a>, Up: <a href="System-Utilities.html" accesskey="u" rel="up">System Utilities</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h3 class="section" id="Controlling-Subprocesses-1"><span>36.5 Controlling Subprocesses<a class="copiable-link" href="#Controlling-Subprocesses-1"> ¶</a></span></h3>
<p>Octave includes some high-level commands like <code class="code">system</code> and
<code class="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’t find any way to do what you need with the
higher-level functions.
</p>
<a class="anchor" id="XREFsystem"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-system"><span><strong class="def-name">system</strong> <code class="def-code-arguments">("<var class="var">string</var>")</code><a class="copiable-link" href="#index-system"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-system-1"><span><strong class="def-name">system</strong> <code class="def-code-arguments">("<var class="var">string</var>", <var class="var">return_output</var>)</code><a class="copiable-link" href="#index-system-1"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-system-2"><span><strong class="def-name">system</strong> <code class="def-code-arguments">("<var class="var">string</var>", <var class="var">return_output</var>, <var class="var">type</var>)</code><a class="copiable-link" href="#index-system-2"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-system-3"><span><code class="def-type">[<var class="var">status</var>, <var class="var">output</var>] =</code> <strong class="def-name">system</strong> <code class="def-code-arguments">(…)</code><a class="copiable-link" href="#index-system-3"> ¶</a></span></dt>
<dd><p>Execute a shell command specified by <var class="var">string</var>.
</p>
<p>If <var class="var">system</var> is called with one or more output arguments, or if the optional
argument <var class="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 class="code">system</code> through the pager, use a command like
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">[~, text] = system ("cmd");
more on;
disp (text);
</pre></div></div>
<p>or
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">more on;
printf ("%s\n", nthargout (2, "system", "cmd"));
</pre></div></div>
<p>If the optional argument <var class="var">type</var> is <code class="code">"async"</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 class="var">type</var> argument is omitted, it defaults to the value
<code class="code">"sync"</code>.
</p>
<p>The <code class="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-preformatted">[status, output] = system ("echo foo & exit 2");
</pre></div>
<p>will set the variable <var class="var">output</var> to the string ‘<samp class="samp">foo</samp>’, and the variable
<var class="var">status</var> to the integer ‘<samp class="samp">2</samp>’.
</p>
<p>For commands run asynchronously, <var class="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 class="file">/bin/sh</samp> for UNIX systems and <samp class="file">cmd.exe</samp> for
Windows systems.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFunix">unix</a>, <a class="ref" href="#XREFdos">dos</a>.
</p></dd></dl>
<a class="anchor" id="XREFunix"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-unix"><span><strong class="def-name">unix</strong> <code class="def-code-arguments">("<var class="var">command</var>")</code><a class="copiable-link" href="#index-unix"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-unix-1"><span><code class="def-type"><var class="var">status</var> =</code> <strong class="def-name">unix</strong> <code class="def-code-arguments">("<var class="var">command</var>")</code><a class="copiable-link" href="#index-unix-1"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-unix-2"><span><code class="def-type">[<var class="var">status</var>, <var class="var">text</var>] =</code> <strong class="def-name">unix</strong> <code class="def-code-arguments">("<var class="var">command</var>")</code><a class="copiable-link" href="#index-unix-2"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-unix-3"><span><code class="def-type">[…] =</code> <strong class="def-name">unix</strong> <code class="def-code-arguments">("<var class="var">command</var>", "-echo")</code><a class="copiable-link" href="#index-unix-3"> ¶</a></span></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 class="var">status</var> and any output in <var class="var">text</var>.
</p>
<p>When called with no output argument, or the <code class="code">"-echo"</code> argument is
given, then <var class="var">text</var> is also sent to standard output.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFdos">dos</a>, <a class="ref" href="#XREFsystem">system</a>, <a class="ref" href="System-Information.html#XREFisunix">isunix</a>, <a class="ref" href="System-Information.html#XREFismac">ismac</a>, <a class="ref" href="System-Information.html#XREFispc">ispc</a>.
</p></dd></dl>
<a class="anchor" id="XREFdos"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-dos"><span><strong class="def-name">dos</strong> <code class="def-code-arguments">("<var class="var">command</var>")</code><a class="copiable-link" href="#index-dos"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-dos-1"><span><code class="def-type"><var class="var">status</var> =</code> <strong class="def-name">dos</strong> <code class="def-code-arguments">("<var class="var">command</var>")</code><a class="copiable-link" href="#index-dos-1"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-dos-2"><span><code class="def-type">[<var class="var">status</var>, <var class="var">text</var>] =</code> <strong class="def-name">dos</strong> <code class="def-code-arguments">("<var class="var">command"</var>)</code><a class="copiable-link" href="#index-dos-2"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-dos-3"><span><code class="def-type">[…] =</code> <strong class="def-name">dos</strong> <code class="def-code-arguments">("<var class="var">command</var>", "-echo")</code><a class="copiable-link" href="#index-dos-3"> ¶</a></span></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 class="var">status</var> and any output in <var class="var">text</var>.
</p>
<p>When called with no output argument, or the <code class="code">"-echo"</code> argument is
given, then <var class="var">text</var> is also sent to standard output.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFunix">unix</a>, <a class="ref" href="#XREFsystem">system</a>, <a class="ref" href="System-Information.html#XREFisunix">isunix</a>, <a class="ref" href="System-Information.html#XREFismac">ismac</a>, <a class="ref" href="System-Information.html#XREFispc">ispc</a>.
</p></dd></dl>
<a class="anchor" id="XREFopen"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-open"><span><strong class="def-name">open</strong> <code class="def-code-arguments"><var class="var">file</var></code><a class="copiable-link" href="#index-open"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-open-1"><span><code class="def-type"><var class="var">output</var> =</code> <strong class="def-name">open</strong> <code class="def-code-arguments">(<var class="var">file</var>)</code><a class="copiable-link" href="#index-open-1"> ¶</a></span></dt>
<dd><p>Open the file <var class="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 class="table">
<dt><code class="code">.m</code></dt>
<dd><p>Open file in the editor. No <var class="var">output</var> value is returned.
</p>
</dd>
<dt><code class="code">.mat</code></dt>
<dt><code class="code">octave-workspace</code></dt>
<dd><p>Open the data file with <code class="code">load</code>. If no return value <var class="var">output</var>
is requested, variables are loaded in the base workspace. Otherwise
<var class="var">output</var> will be a structure containing loaded data.
See <a class="xref" href="Simple-File-I_002fO.html#XREFload">load function</a>.
</p>
</dd>
<dt><code class="code">.ofig</code></dt>
<dd><p>Open the figure with <code class="code">hgload</code>.
See <a class="xref" href="Printing-and-Saving-Plots.html#XREFhgload">hgload function</a>.
</p>
</dd>
<dt><code class="code">.fig, .ofig</code></dt>
<dd><p>Load the figure
</p>
</dd>
<dt><code class="code">.exe</code></dt>
<dd><p>Execute the program (on Windows systems only). No <var class="var">output</var> value
is returned.
</p></dd>
</dl>
<p>Custom file extensions may also be handled if a function <code class="code">openxxx</code>,
where <code class="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 class="code">".dat"</code> data files in the base workspace, as is done by
default for <code class="code">".mat"</code> files, one may define
<code class="code">"opendat.m"</code> with the following contents:
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">function retval = opendat (fname)
evalin ("base", sprintf ("load ('%s');", fname));
endfunction
</pre></div></div>
<p>Other file types are opened in the appropriate external application.
</p></dd></dl>
<a class="anchor" id="XREFperl"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-perl"><span><code class="def-type"><var class="var">output</var> =</code> <strong class="def-name">perl</strong> <code class="def-code-arguments">(<var class="var">scriptfile</var>)</code><a class="copiable-link" href="#index-perl"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-perl-1"><span><code class="def-type"><var class="var">output</var> =</code> <strong class="def-name">perl</strong> <code class="def-code-arguments">(<var class="var">scriptfile</var>, <var class="var">argument1</var>, <var class="var">argument2</var>, …)</code><a class="copiable-link" href="#index-perl-1"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-perl-2"><span><code class="def-type">[<var class="var">output</var>, <var class="var">status</var>] =</code> <strong class="def-name">perl</strong> <code class="def-code-arguments">(…)</code><a class="copiable-link" href="#index-perl-2"> ¶</a></span></dt>
<dd><p>Invoke Perl script <var class="var">scriptfile</var>, possibly with a list of command line
arguments.
</p>
<p>Return output in <var class="var">output</var> and optional status in <var class="var">status</var>. If
<var class="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 class="strong">See also:</strong> <a class="ref" href="#XREFsystem">system</a>, <a class="ref" href="#XREFpython">python</a>.
</p></dd></dl>
<a class="anchor" id="XREFpython"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-python"><span><code class="def-type"><var class="var">output</var> =</code> <strong class="def-name">python</strong> <code class="def-code-arguments">(<var class="var">scriptfile</var>)</code><a class="copiable-link" href="#index-python"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-python-1"><span><code class="def-type"><var class="var">output</var> =</code> <strong class="def-name">python</strong> <code class="def-code-arguments">(<var class="var">scriptfile</var>, <var class="var">argument1</var>, <var class="var">argument2</var>, …)</code><a class="copiable-link" href="#index-python-1"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-python-2"><span><code class="def-type">[<var class="var">output</var>, <var class="var">status</var>] =</code> <strong class="def-name">python</strong> <code class="def-code-arguments">(…)</code><a class="copiable-link" href="#index-python-2"> ¶</a></span></dt>
<dd><p>Invoke Python script <var class="var">scriptfile</var>, possibly with a list of command line
arguments.
</p>
<p>Return output in <var class="var">output</var> and optional status in <var class="var">status</var>. If
<var class="var">scriptfile</var> is not an absolute filename it is searched for in the
current directory and then in the Octave loadpath.
</p>
<p>Programming Note: On UNIX systems, the script will be executed by
<code class="command">python3</code> and on Windows by <code class="command">python</code>. You can override
these defaults by setting the <code class="env">PYTHON</code> environment variable, for example
from within Octave using <code class="code">setenv PYTHON /usr/local/bin/python3</code>.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFsystem">system</a>, <a class="ref" href="#XREFperl">perl</a>.
</p></dd></dl>
<a class="anchor" id="XREFpopen"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-popen"><span><code class="def-type"><var class="var">fid</var> =</code> <strong class="def-name">popen</strong> <code class="def-code-arguments">(<var class="var">command</var>, <var class="var">mode</var>)</code><a class="copiable-link" href="#index-popen"> ¶</a></span></dt>
<dd><p>Start a process and create a pipe.
</p>
<p>The name of the command to run is given by <var class="var">command</var>. The argument
<var class="var">mode</var> may be
</p>
<dl class="table">
<dt><code class="code">"r"</code></dt>
<dd><p>The pipe will be connected to the standard output of the process, and
open for reading.
</p>
</dd>
<dt><code class="code">"w"</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 class="var">fid</var>.
</p>
<p>For example:
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">fid = popen ("ls -ltr / | tail -3", "r");
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></div>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFpopen2">popen2</a>.
</p></dd></dl>
<a class="anchor" id="XREFpclose"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-pclose"><span><code class="def-type"><var class="var">status</var> =</code> <strong class="def-name">pclose</strong> <code class="def-code-arguments">(<var class="var">fid</var>)</code><a class="copiable-link" href="#index-pclose"> ¶</a></span></dt>
<dd><p>Close a file identifier <var class="var">fid</var> that was opened by <code class="code">popen</code>.
</p>
<p>If successful, <code class="code">fclose</code> returns 0, otherwise, it returns -1.
</p>
<p>Programming Note: The function <code class="code">fclose</code> may also be used for the same
purpose.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="Opening-and-Closing-Files.html#XREFfclose">fclose</a>, <a class="ref" href="#XREFpopen">popen</a>.
</p></dd></dl>
<a class="anchor" id="XREFpopen2"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-popen2"><span><code class="def-type">[<var class="var">in</var>, <var class="var">out</var>, <var class="var">pid</var>] =</code> <strong class="def-name">popen2</strong> <code class="def-code-arguments">(<var class="var">command</var>, <var class="var">args</var>)</code><a class="copiable-link" href="#index-popen2"> ¶</a></span></dt>
<dd><p>Start a subprocess with two-way communication.
</p>
<p>The name of the process is given by <var class="var">command</var>, and <var class="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 class="var">in</var> and <var class="var">out</var>. If execution of the command is
successful, <var class="var">pid</var> contains the process ID of the subprocess. Otherwise,
<var class="var">pid</var> is −1.
</p>
<p>For example:
</p>
<div class="example">
<pre class="example-preformatted">[in, out, pid] = popen2 ("sort", "-r");
fputs (in, "these\nare\nsome\nstrings\n");
fclose (in);
EAGAIN = errno ("EAGAIN");
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 class="code">popen2</code>, unlike <code class="code">popen</code>, will not "reap"
the child process. If you don’t use <code class="code">waitpid</code> to check the child’s
exit status, it will linger until Octave exits.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFpopen">popen</a>, <a class="ref" href="#XREFwaitpid">waitpid</a>.
</p></dd></dl>
<a class="anchor" id="XREFEXEC_005fPATH"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-EXEC_005fPATH"><span><code class="def-type"><var class="var">val</var> =</code> <strong class="def-name">EXEC_PATH</strong> <code class="def-code-arguments">()</code><a class="copiable-link" href="#index-EXEC_005fPATH"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-EXEC_005fPATH-1"><span><code class="def-type"><var class="var">old_val</var> =</code> <strong class="def-name">EXEC_PATH</strong> <code class="def-code-arguments">(<var class="var">new_val</var>)</code><a class="copiable-link" href="#index-EXEC_005fPATH-1"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-EXEC_005fPATH-2"><span><code class="def-type"><var class="var">old_val</var> =</code> <strong class="def-name">EXEC_PATH</strong> <code class="def-code-arguments">(<var class="var">new_val</var>, "local")</code><a class="copiable-link" href="#index-EXEC_005fPATH-2"> ¶</a></span></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 class="env">OCTAVE_EXEC_PATH</code><!-- /@w -->, but that value can be overridden by the command
line argument <samp class="option">--exec-path PATH</samp>.
</p>
<p>When called from inside a function with the <code class="code">"local"</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 class="strong">See also:</strong> <a class="ref" href="Loading-and-Saving-Images.html#XREFIMAGE_005fPATH">IMAGE_PATH</a>, <a class="ref" href="System-Information.html#XREFOCTAVE_005fHOME">OCTAVE_HOME</a>, <a class="ref" 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 class="code">popen2</code>.
</p>
<a class="anchor" id="XREFfork"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-fork"><span><code class="def-type">[<var class="var">pid</var>, <var class="var">msg</var>] =</code> <strong class="def-name">fork</strong> <code class="def-code-arguments">()</code><a class="copiable-link" href="#index-fork"> ¶</a></span></dt>
<dd><p>Create a copy of the current process.
</p>
<p>Fork can return one of the following values:
</p>
<dl class="table">
<dt>> 0</dt>
<dd><p>You are in the parent process. The value returned from <code class="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 class="code">exec</code> to start another
process. If that fails, you should probably call <code class="code">exit</code>.
</p>
</dd>
<dt>< 0</dt>
<dd><p>The call to <code class="code">fork</code> failed for some reason. You must take evasive
action. A system dependent error message will be waiting in <var class="var">msg</var>.
</p></dd>
</dl>
</dd></dl>
<a class="anchor" id="XREFexec"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-exec"><span><code class="def-type">[<var class="var">err</var>, <var class="var">msg</var>] =</code> <strong class="def-name">exec</strong> <code class="def-code-arguments">(<var class="var">file</var>, <var class="var">args</var>)</code><a class="copiable-link" href="#index-exec"> ¶</a></span></dt>
<dd><p>Replace current process with a new process.
</p>
<p>Calling <code class="code">exec</code> without first calling <code class="code">fork</code> will terminate your
current Octave process and replace it with the program named by <var class="var">file</var>.
For example,
</p>
<div class="example">
<pre class="example-preformatted">exec ("ls", "-l")
</pre></div>
<p>will run <code class="code">ls</code> and return you to your shell prompt.
</p>
<p>If successful, <code class="code">exec</code> does not return. If <code class="code">exec</code> does return,
<var class="var">err</var> will be nonzero, and <var class="var">msg</var> will contain a system-dependent
error message.
</p></dd></dl>
<a class="anchor" id="XREFpipe"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-pipe"><span><code class="def-type">[<var class="var">read_fd</var>, <var class="var">write_fd</var>, <var class="var">err</var>, <var class="var">msg</var>] =</code> <strong class="def-name">pipe</strong> <code class="def-code-arguments">()</code><a class="copiable-link" href="#index-pipe"> ¶</a></span></dt>
<dd><p>Create a pipe and return the reading and writing ends of the pipe into
<var class="var">read_fd</var> and <var class="var">write_fd</var> respectively.
</p>
<p>If successful, <var class="var">err</var> is 0 and <var class="var">msg</var> is an empty string.
Otherwise, <var class="var">err</var> is nonzero and <var class="var">msg</var> contains a system-dependent
error message.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="Filesystem-Utilities.html#XREFmkfifo">mkfifo</a>.
</p></dd></dl>
<a class="anchor" id="XREFdup2"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-dup2"><span><code class="def-type">[<var class="var">fid</var>, <var class="var">msg</var>] =</code> <strong class="def-name">dup2</strong> <code class="def-code-arguments">(<var class="var">old</var>, <var class="var">new</var>)</code><a class="copiable-link" href="#index-dup2"> ¶</a></span></dt>
<dd><p>Duplicate a file descriptor.
</p>
<p>If successful, <var class="var">fid</var> is greater than zero and contains the new file ID.
Otherwise, <var class="var">fid</var> is negative and <var class="var">msg</var> contains a system-dependent
error message.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="Opening-and-Closing-Files.html#XREFfopen">fopen</a>, <a class="ref" href="Opening-and-Closing-Files.html#XREFfclose">fclose</a>, <a class="ref" href="#XREFfcntl">fcntl</a>.
</p></dd></dl>
<a class="anchor" id="XREFwaitpid"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-waitpid"><span><code class="def-type">[<var class="var">pid</var>, <var class="var">status</var>, <var class="var">msg</var>] =</code> <strong class="def-name">waitpid</strong> <code class="def-code-arguments">(<var class="var">pid</var>, <var class="var">options</var>)</code><a class="copiable-link" href="#index-waitpid"> ¶</a></span></dt>
<dd><p>Wait for process <var class="var">pid</var> to terminate.
</p>
<p>The <var class="var">pid</var> argument can be:
</p>
<dl class="table">
<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>> 0</dt>
<dd><p>Wait for termination of the child process with ID <var class="var">pid</var>.
</p></dd>
</dl>
<p>The <var class="var">options</var> argument can be a bitwise OR of zero or more of the
following constants:
</p>
<dl class="table">
<dt><code class="code">0</code></dt>
<dd><p>Wait until signal is received or a child process exits (this is the default
if the <var class="var">options</var> argument is missing).
</p>
</dd>
<dt><code class="code">WNOHANG</code></dt>
<dd><p>Do not hang if status is not immediately available.
</p>
</dd>
<dt><code class="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 class="code">WCONTINUE</code></dt>
<dd><p>Return if a stopped child has been resumed by delivery of <code class="code">SIGCONT</code>.
This value may not be meaningful on all systems.
</p></dd>
</dl>
<p>If the returned value of <var class="var">pid</var> is greater than 0, it is the process ID
of the child process that exited. If an error occurs, <var class="var">pid</var> will be
less than zero and <var class="var">msg</var> will contain a system-dependent error message.
The value of <var class="var">status</var> contains additional system-dependent information
about the subprocess that exited.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFWCONTINUE">WCONTINUE</a>, <a class="ref" href="#XREFWCOREDUMP">WCOREDUMP</a>, <a class="ref" href="#XREFWEXITSTATUS">WEXITSTATUS</a>, <a class="ref" href="#XREFWIFCONTINUED">WIFCONTINUED</a>, <a class="ref" href="#XREFWIFSIGNALED">WIFSIGNALED</a>, <a class="ref" href="#XREFWIFSTOPPED">WIFSTOPPED</a>, <a class="ref" href="#XREFWNOHANG">WNOHANG</a>, <a class="ref" href="#XREFWSTOPSIG">WSTOPSIG</a>, <a class="ref" href="#XREFWTERMSIG">WTERMSIG</a>, <a class="ref" href="#XREFWUNTRACED">WUNTRACED</a>.
</p></dd></dl>
<a class="anchor" id="XREFWCONTINUE"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-WCONTINUE"><span><code class="def-type"><var class="var">v</var> =</code> <strong class="def-name">WCONTINUE</strong> <code class="def-code-arguments">()</code><a class="copiable-link" href="#index-WCONTINUE"> ¶</a></span></dt>
<dd><p>Return the numerical value of the <code class="code">WCONTINUE</code> macro.
</p>
<p><code class="code">WCONTINUE</code> is the option argument that may be passed to
<code class="code">waitpid</code> to indicate that it should also return if a stopped child
has been resumed by delivery of a <code class="code">SIGCONT</code> signal.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFwaitpid">waitpid</a>, <a class="ref" href="#XREFWNOHANG">WNOHANG</a>, <a class="ref" href="#XREFWUNTRACED">WUNTRACED</a>.
</p></dd></dl>
<a class="anchor" id="XREFWCOREDUMP"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-WCOREDUMP"><span><code class="def-type"><var class="var">tf</var> =</code> <strong class="def-name">WCOREDUMP</strong> <code class="def-code-arguments">(<var class="var">status</var>)</code><a class="copiable-link" href="#index-WCOREDUMP"> ¶</a></span></dt>
<dd><p>Given <var class="var">status</var> from a call to <code class="code">waitpid</code>, return
true if the child produced a core dump.
</p>
<p>This function should only be employed if <code class="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 class="strong">See also:</strong> <a class="ref" href="#XREFwaitpid">waitpid</a>, <a class="ref" href="#XREFWIFEXITED">WIFEXITED</a>, <a class="ref" href="#XREFWEXITSTATUS">WEXITSTATUS</a>, <a class="ref" href="#XREFWIFSIGNALED">WIFSIGNALED</a>, <a class="ref" href="#XREFWTERMSIG">WTERMSIG</a>, <a class="ref" href="#XREFWIFSTOPPED">WIFSTOPPED</a>, <a class="ref" href="#XREFWSTOPSIG">WSTOPSIG</a>, <a class="ref" href="#XREFWIFCONTINUED">WIFCONTINUED</a>.
</p></dd></dl>
<a class="anchor" id="XREFWEXITSTATUS"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-WEXITSTATUS"><span><code class="def-type"><var class="var">tf</var> =</code> <strong class="def-name">WEXITSTATUS</strong> <code class="def-code-arguments">(<var class="var">status</var>)</code><a class="copiable-link" href="#index-WEXITSTATUS"> ¶</a></span></dt>
<dd><p>Given <var class="var">status</var> from a call to <code class="code">waitpid</code>, return
the exit status of the child.
</p>
<p>This function should only be employed if <code class="code">WIFEXITED</code> returned true.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFwaitpid">waitpid</a>, <a class="ref" href="#XREFWIFEXITED">WIFEXITED</a>, <a class="ref" href="#XREFWIFSIGNALED">WIFSIGNALED</a>, <a class="ref" href="#XREFWTERMSIG">WTERMSIG</a>, <a class="ref" href="#XREFWCOREDUMP">WCOREDUMP</a>, <a class="ref" href="#XREFWIFSTOPPED">WIFSTOPPED</a>, <a class="ref" href="#XREFWSTOPSIG">WSTOPSIG</a>, <a class="ref" href="#XREFWIFCONTINUED">WIFCONTINUED</a>.
</p></dd></dl>
<a class="anchor" id="XREFWIFCONTINUED"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-WIFCONTINUED"><span><code class="def-type"><var class="var">tf</var> =</code> <strong class="def-name">WIFCONTINUED</strong> <code class="def-code-arguments">(<var class="var">status</var>)</code><a class="copiable-link" href="#index-WIFCONTINUED"> ¶</a></span></dt>
<dd><p>Given <var class="var">status</var> from a call to <code class="code">waitpid</code>, return
true if the child process was resumed by delivery of <code class="code">SIGCONT</code>.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFwaitpid">waitpid</a>, <a class="ref" href="#XREFWIFEXITED">WIFEXITED</a>, <a class="ref" href="#XREFWEXITSTATUS">WEXITSTATUS</a>, <a class="ref" href="#XREFWIFSIGNALED">WIFSIGNALED</a>, <a class="ref" href="#XREFWTERMSIG">WTERMSIG</a>, <a class="ref" href="#XREFWCOREDUMP">WCOREDUMP</a>, <a class="ref" href="#XREFWIFSTOPPED">WIFSTOPPED</a>, <a class="ref" href="#XREFWSTOPSIG">WSTOPSIG</a>.
</p></dd></dl>
<a class="anchor" id="XREFWIFSIGNALED"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-WIFSIGNALED"><span><code class="def-type"><var class="var">tf</var> =</code> <strong class="def-name">WIFSIGNALED</strong> <code class="def-code-arguments">(<var class="var">status</var>)</code><a class="copiable-link" href="#index-WIFSIGNALED"> ¶</a></span></dt>
<dd><p>Given <var class="var">status</var> from a call to <code class="code">waitpid</code>, return
true if the child process was terminated by a signal.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFwaitpid">waitpid</a>, <a class="ref" href="#XREFWIFEXITED">WIFEXITED</a>, <a class="ref" href="#XREFWEXITSTATUS">WEXITSTATUS</a>, <a class="ref" href="#XREFWTERMSIG">WTERMSIG</a>, <a class="ref" href="#XREFWCOREDUMP">WCOREDUMP</a>, <a class="ref" href="#XREFWIFSTOPPED">WIFSTOPPED</a>, <a class="ref" href="#XREFWSTOPSIG">WSTOPSIG</a>, <a class="ref" href="#XREFWIFCONTINUED">WIFCONTINUED</a>.
</p></dd></dl>
<a class="anchor" id="XREFWIFSTOPPED"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-WIFSTOPPED"><span><code class="def-type"><var class="var">tf</var> =</code> <strong class="def-name">WIFSTOPPED</strong> <code class="def-code-arguments">(<var class="var">status</var>)</code><a class="copiable-link" href="#index-WIFSTOPPED"> ¶</a></span></dt>
<dd><p>Given <var class="var">status</var> from a call to <code class="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 class="code">WUNTRACED</code> or when
the child is being traced (see ptrace(2)).
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFwaitpid">waitpid</a>, <a class="ref" href="#XREFWIFEXITED">WIFEXITED</a>, <a class="ref" href="#XREFWEXITSTATUS">WEXITSTATUS</a>, <a class="ref" href="#XREFWIFSIGNALED">WIFSIGNALED</a>, <a class="ref" href="#XREFWTERMSIG">WTERMSIG</a>, <a class="ref" href="#XREFWCOREDUMP">WCOREDUMP</a>, <a class="ref" href="#XREFWSTOPSIG">WSTOPSIG</a>, <a class="ref" href="#XREFWIFCONTINUED">WIFCONTINUED</a>.
</p></dd></dl>
<a class="anchor" id="XREFWIFEXITED"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-WIFEXITED"><span><code class="def-type"><var class="var">tf</var> =</code> <strong class="def-name">WIFEXITED</strong> <code class="def-code-arguments">(<var class="var">status</var>)</code><a class="copiable-link" href="#index-WIFEXITED"> ¶</a></span></dt>
<dd><p>Given <var class="var">status</var> from a call to <code class="code">waitpid</code>, return
true if the child terminated normally.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFwaitpid">waitpid</a>, <a class="ref" href="#XREFWEXITSTATUS">WEXITSTATUS</a>, <a class="ref" href="#XREFWIFSIGNALED">WIFSIGNALED</a>, <a class="ref" href="#XREFWTERMSIG">WTERMSIG</a>, <a class="ref" href="#XREFWCOREDUMP">WCOREDUMP</a>, <a class="ref" href="#XREFWIFSTOPPED">WIFSTOPPED</a>, <a class="ref" href="#XREFWSTOPSIG">WSTOPSIG</a>, <a class="ref" href="#XREFWIFCONTINUED">WIFCONTINUED</a>.
</p></dd></dl>
<a class="anchor" id="XREFWNOHANG"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-WNOHANG"><span><code class="def-type"><var class="var">v</var> =</code> <strong class="def-name">WNOHANG</strong> <code class="def-code-arguments">()</code><a class="copiable-link" href="#index-WNOHANG"> ¶</a></span></dt>
<dd><p>Return the numerical value of the <code class="code">WNOHANG</code> macro.
</p>
<p><code class="code">WNOHANG</code> is the option argument that may be passed to
<code class="code">waitpid</code> to indicate that it should return its status immediately
instead of waiting for a process to exit.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFwaitpid">waitpid</a>, <a class="ref" href="#XREFWUNTRACED">WUNTRACED</a>, <a class="ref" href="#XREFWCONTINUE">WCONTINUE</a>.
</p></dd></dl>
<a class="anchor" id="XREFWSTOPSIG"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-WSTOPSIG"><span><code class="def-type"><var class="var">tf</var> =</code> <strong class="def-name">WSTOPSIG</strong> <code class="def-code-arguments">(<var class="var">status</var>)</code><a class="copiable-link" href="#index-WSTOPSIG"> ¶</a></span></dt>
<dd><p>Given <var class="var">status</var> from a call to <code class="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 class="code">WIFSTOPPED</code> returned true.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFwaitpid">waitpid</a>, <a class="ref" href="#XREFWIFEXITED">WIFEXITED</a>, <a class="ref" href="#XREFWEXITSTATUS">WEXITSTATUS</a>, <a class="ref" href="#XREFWIFSIGNALED">WIFSIGNALED</a>, <a class="ref" href="#XREFWTERMSIG">WTERMSIG</a>, <a class="ref" href="#XREFWCOREDUMP">WCOREDUMP</a>, <a class="ref" href="#XREFWIFSTOPPED">WIFSTOPPED</a>, <a class="ref" href="#XREFWIFCONTINUED">WIFCONTINUED</a>.
</p></dd></dl>
<a class="anchor" id="XREFWTERMSIG"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-WTERMSIG"><span><code class="def-type"><var class="var">tf</var> =</code> <strong class="def-name">WTERMSIG</strong> <code class="def-code-arguments">(<var class="var">status</var>)</code><a class="copiable-link" href="#index-WTERMSIG"> ¶</a></span></dt>
<dd><p>Given <var class="var">status</var> from a call to <code class="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 class="code">WIFSIGNALED</code> returned true.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFwaitpid">waitpid</a>, <a class="ref" href="#XREFWIFEXITED">WIFEXITED</a>, <a class="ref" href="#XREFWEXITSTATUS">WEXITSTATUS</a>, <a class="ref" href="#XREFWIFSIGNALED">WIFSIGNALED</a>, <a class="ref" href="#XREFWCOREDUMP">WCOREDUMP</a>, <a class="ref" href="#XREFWIFSTOPPED">WIFSTOPPED</a>, <a class="ref" href="#XREFWSTOPSIG">WSTOPSIG</a>, <a class="ref" href="#XREFWIFCONTINUED">WIFCONTINUED</a>.
</p></dd></dl>
<a class="anchor" id="XREFWUNTRACED"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-WUNTRACED"><span><code class="def-type"><var class="var">v</var> =</code> <strong class="def-name">WUNTRACED</strong> <code class="def-code-arguments">()</code><a class="copiable-link" href="#index-WUNTRACED"> ¶</a></span></dt>
<dd><p>Return the numerical value of the <code class="code">WUNTRACED</code> macro.
</p>
<p><code class="code">WUNTRACED</code> is the option argument that may be passed to
<code class="code">waitpid</code> to indicate that it should also return if the child
process has stopped but is not traced via the <code class="code">ptrace</code> system call
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFwaitpid">waitpid</a>, <a class="ref" href="#XREFWNOHANG">WNOHANG</a>, <a class="ref" href="#XREFWCONTINUE">WCONTINUE</a>.
</p></dd></dl>
<a class="anchor" id="XREFfcntl"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-fcntl"><span><strong class="def-name">fcntl</strong> <code class="def-code-arguments">(<var class="var">fid</var>, <var class="var">request</var>, <var class="var">arg</var>)</code><a class="copiable-link" href="#index-fcntl"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-fcntl-1"><span><code class="def-type">[<var class="var">status</var>, <var class="var">msg</var>] =</code> <strong class="def-name">fcntl</strong> <code class="def-code-arguments">(<var class="var">fid</var>, <var class="var">request</var>, <var class="var">arg</var>)</code><a class="copiable-link" href="#index-fcntl-1"> ¶</a></span></dt>
<dd><p>Change the properties of the open file <var class="var">fid</var>.
</p>
<p>The following values may be passed as <var class="var">request</var>:
</p>
<dl class="vtable">
<dt><a id="index-F_005fDUPFD"></a><span><code class="code">F_DUPFD</code><a class="copiable-link" href="#index-F_005fDUPFD"> ¶</a></span></dt>
<dd><p>Return a duplicate file descriptor.
</p>
</dd>
<dt><a id="index-F_005fGETFD"></a><span><code class="code">F_GETFD</code><a class="copiable-link" href="#index-F_005fGETFD"> ¶</a></span></dt>
<dd><p>Return the file descriptor flags for <var class="var">fid</var>.
</p>
</dd>
<dt><a id="index-F_005fSETFD"></a><span><code class="code">F_SETFD</code><a class="copiable-link" href="#index-F_005fSETFD"> ¶</a></span></dt>
<dd><p>Set the file descriptor flags for <var class="var">fid</var>.
</p>
</dd>
<dt><a id="index-F_005fGETFL"></a><span><code class="code">F_GETFL</code><a class="copiable-link" href="#index-F_005fGETFL"> ¶</a></span></dt>
<dd><p>Return the file status flags for <var class="var">fid</var>. The following codes may be
returned (some of the flags may be undefined on some systems).
</p>
<dl class="vtable">
<dt><a id="index-O_005fRDONLY"></a><span><code class="code">O_RDONLY</code><a class="copiable-link" href="#index-O_005fRDONLY"> ¶</a></span></dt>
<dd><p>Open for reading only.
</p>
</dd>
<dt><a id="index-O_005fWRONLY"></a><span><code class="code">O_WRONLY</code><a class="copiable-link" href="#index-O_005fWRONLY"> ¶</a></span></dt>
<dd><p>Open for writing only.
</p>
</dd>
<dt><a id="index-O_005fRDWR"></a><span><code class="code">O_RDWR</code><a class="copiable-link" href="#index-O_005fRDWR"> ¶</a></span></dt>
<dd><p>Open for reading and writing.
</p>
</dd>
<dt><a id="index-O_005fAPPEND"></a><span><code class="code">O_APPEND</code><a class="copiable-link" href="#index-O_005fAPPEND"> ¶</a></span></dt>
<dd><p>Append on each write.
</p>
</dd>
<dt><a id="index-O_005fCREAT"></a><span><code class="code">O_CREAT</code><a class="copiable-link" href="#index-O_005fCREAT"> ¶</a></span></dt>
<dd><p>Create the file if it does not exist.
</p>
</dd>
<dt><a id="index-O_005fNONBLOCK"></a><span><code class="code">O_NONBLOCK</code><a class="copiable-link" href="#index-O_005fNONBLOCK"> ¶</a></span></dt>
<dd><p>Non-blocking mode.
</p>
</dd>
<dt><a id="index-O_005fSYNC"></a><span><code class="code">O_SYNC</code><a class="copiable-link" href="#index-O_005fSYNC"> ¶</a></span></dt>
<dd><p>Wait for writes to complete.
</p>
</dd>
<dt><a id="index-O_005fASYNC"></a><span><code class="code">O_ASYNC</code><a class="copiable-link" href="#index-O_005fASYNC"> ¶</a></span></dt>
<dd><p>Asynchronous I/O.
</p></dd>
</dl>
</dd>
<dt><a id="index-F_005fSETFL"></a><span><code class="code">F_SETFL</code><a class="copiable-link" href="#index-F_005fSETFL"> ¶</a></span></dt>
<dd><p>Set the file status flags for <var class="var">fid</var> to the value specified by <var class="var">arg</var>.
The only flags that can be changed are <code class="code">O_APPEND</code><!-- /@w --> and
<code class="code">O_NONBLOCK</code><!-- /@w -->.
</p></dd>
</dl>
<p>If successful, <var class="var">status</var> is 0 and <var class="var">msg</var> is an empty string. Otherwise,
<var class="var">status</var> is -1 and <var class="var">msg</var> contains a system-dependent error
message.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="Opening-and-Closing-Files.html#XREFfopen">fopen</a>, <a class="ref" href="#XREFdup2">dup2</a>.
</p></dd></dl>
<a class="anchor" id="XREFkill"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-kill"><span><strong class="def-name">kill</strong> <code class="def-code-arguments">(<var class="var">pid</var>, <var class="var">sig</var>)</code><a class="copiable-link" href="#index-kill"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-kill-1"><span><code class="def-type">[<var class="var">status</var>, <var class="var">msg</var>] =</code> <strong class="def-name">kill</strong> <code class="def-code-arguments">(<var class="var">pid</var>, <var class="var">sig</var>)</code><a class="copiable-link" href="#index-kill-1"> ¶</a></span></dt>
<dd><p>Send signal <var class="var">sig</var> to process <var class="var">pid</var>.
</p>
<p>If <var class="var">pid</var> is positive, then signal <var class="var">sig</var> is sent to <var class="var">pid</var>.
</p>
<p>If <var class="var">pid</var> is 0, then signal <var class="var">sig</var> is sent to every process in the
process group of the current process.
</p>
<p>If <var class="var">pid</var> is -1, then signal <var class="var">sig</var> is sent to every process except
process 1.
</p>
<p>If <var class="var">pid</var> is less than -1, then signal <var class="var">sig</var> is sent to every process in
the process group <var class="var">-pid</var>.
</p>
<p>If <var class="var">sig</var> is 0, then no signal is sent, but error checking is still
performed.
</p>
<p>If successful, <var class="var">status</var> is 0 and <var class="var">msg</var> is an empty string.
Otherwise, <var class="var">status</var> is -1 and <var class="var">msg</var> contains a system-dependent
error message.
</p></dd></dl>
<a class="anchor" id="XREFSIG"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-SIG"><span><code class="def-type"><var class="var">S</var> =</code> <strong class="def-name">SIG</strong> <code class="def-code-arguments">()</code><a class="copiable-link" href="#index-SIG"> ¶</a></span></dt>
<dd><p>Return a structure containing Unix signal names and their defined values.
</p></dd></dl>
</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="Process-ID-Information.html">Process, Group, and User IDs</a>, Previous: <a href="Networking-Utilities.html">Networking Utilities</a>, Up: <a href="System-Utilities.html">System Utilities</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>
|