File: Controlling-Subprocesses.html

package info (click to toggle)
octave 3.8.2-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 84,396 kB
  • ctags: 45,547
  • sloc: cpp: 293,356; ansic: 42,041; fortran: 23,669; sh: 13,629; objc: 7,890; yacc: 7,093; lex: 3,442; java: 2,125; makefile: 1,589; perl: 1,009; awk: 974; xml: 34
file content (650 lines) | stat: -rw-r--r-- 31,241 bytes parent folder | download | duplicates (3)
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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
<head>
<title>GNU Octave: Controlling Subprocesses</title>

<meta name="description" content="GNU Octave: Controlling Subprocesses">
<meta name="keywords" content="GNU Octave: Controlling Subprocesses">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<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.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.indentedblock {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
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.nocodebreak {white-space:nowrap}
span.nolinebreak {white-space:nowrap}
span.roman {font-family:serif; font-weight:normal}
span.sansserif {font-family:sans-serif; font-weight:normal}
ul.no-bullet {list-style: none}
-->
</style>


</head>

<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<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>Built-in Function: <em></em> <strong>system</strong> <em>(&quot;<var>string</var>&quot;)</em></dt>
<dt><a name="index-system-1"></a>Built-in Function: <em></em> <strong>system</strong> <em>(&quot;<var>string</var>&quot;, <var>return_output</var>)</em></dt>
<dt><a name="index-system-2"></a>Built-in Function: <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>Built-in Function: <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>.
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">[output, text] = system (&quot;cmd&quot;);
disp (text);
</pre></div>

<p>or
</p>
<div class="example">
<pre class="example">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; exit 2&quot;);
</pre></div>

<p>will set the variable <code>output</code> to the string &lsquo;<samp>foo</samp>&rsquo;, and the
variable <code>status</code> 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><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>Function File: <em></em> <strong>unix</strong> <em>(&quot;<var>command</var>&quot;)</em></dt>
<dt><a name="index-unix-1"></a>Function File: <em><var>status</var> =</em> <strong>unix</strong> <em>(&quot;<var>command</var>&quot;)</em></dt>
<dt><a name="index-unix-2"></a>Function File: <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>Function File: <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.  Return the exit status of the program
in <var>status</var> and any output from the command in <var>text</var>.
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#XREFispc">ispc</a>.
</p></dd></dl>


<a name="XREFdos"></a><dl>
<dt><a name="index-dos"></a>Function File: <em></em> <strong>dos</strong> <em>(&quot;<var>command</var>&quot;)</em></dt>
<dt><a name="index-dos-1"></a>Function File: <em><var>status</var> =</em> <strong>dos</strong> <em>(&quot;<var>command</var>&quot;)</em></dt>
<dt><a name="index-dos-2"></a>Function File: <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>Function File: <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.  Return the exit status of the program
in <var>status</var> and any output from the command in <var>text</var>.
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#XREFispc">ispc</a>.
</p></dd></dl>


<a name="XREFperl"></a><dl>
<dt><a name="index-perl"></a>Function File: <em><var>output</var> =</em> <strong>perl</strong> <em>(<var>scriptfile</var>)</em></dt>
<dt><a name="index-perl-1"></a>Function File: <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>Function File: <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.  Return output in <var>output</var> and optional status in
<var>status</var>.  If <var>scriptfile</var> is not an absolute file name it is
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>Function File: <em><var>output</var> =</em> <strong>python</strong> <em>(<var>scriptfile</var>)</em></dt>
<dt><a name="index-python-1"></a>Function File: <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>Function File: <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.  Return output in <var>output</var> and optional status in
<var>status</var>.  If <var>scriptfile</var> is not an absolute file name it is
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>Built-in Function: <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.  The name of the command to run is
given by <var>command</var>.  The file identifier corresponding to the input
or output stream of the process is returned in <var>fid</var>.  The argument
<var>mode</var> may be
</p>
<dl compact="compact">
<dt><code><code>&quot;r&quot;</code></code></dt>
<dd><p>The pipe will be connected to the standard output of the process, and
open for reading.
</p>
</dd>
<dt><code><code>&quot;w&quot;</code></code></dt>
<dd><p>The pipe will be connected to the standard input of the process, and
open for writing.
</p></dd>
</dl>

<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>
</dd></dl>


<a name="XREFpclose"></a><dl>
<dt><a name="index-pclose"></a>Built-in Function: <em></em> <strong>pclose</strong> <em>(<var>fid</var>)</em></dt>
<dd><p>Close a file identifier that was opened by <code>popen</code>.  You may also
use <code>fclose</code> for the same purpose.
</p></dd></dl>


<a name="XREFpopen2"></a><dl>
<dt><a name="index-popen2"></a>Built-in Function: <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.  The name of the process
is given by <var>command</var>, and <var>args</var> is an array of strings
containing options for the command.  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)
    sleep (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>Built-in Function: <em><var>val</var> =</em> <strong>EXEC_PATH</strong> <em>()</em></dt>
<dt><a name="index-EXEC_005fPATH-1"></a>Built-in Function: <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>Built-in Function: <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.  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>.
</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>Built-in Function: <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>Built-in Function: <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.  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>Built-in Function: <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>Built-in Function: <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></dd></dl>


<a name="XREFwaitpid"></a><dl>
<dt><a name="index-waitpid"></a>Built-in Function: <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.  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>Built-in Function: <em></em> <strong>WCONTINUE</strong> <em>()</em></dt>
<dd><p>Return the numerical value of 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>Built-in Function: <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.  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>Built-in Function: <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.  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>Built-in Function: <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>Built-in Function: <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>Built-in Function: <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; 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>Built-in Function: <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>Built-in Function: <em></em> <strong>WNOHANG</strong> <em>()</em></dt>
<dd><p>Return the numerical value of 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>Built-in Function: <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.  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>Built-in Function: <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.  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>Built-in Function: <em></em> <strong>WUNTRACED</strong> <em>()</em></dt>
<dd><p>Return the numerical value of 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>Built-in Function: <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>.  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></dd></dl>


<a name="XREFkill"></a><dl>
<dt><a name="index-kill"></a>Built-in Function: <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>Built-in Function: <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>