| 1 |
.TH FORK 3am "Feb 02 2018" "Free Software Foundation" "GNU Awk Extension Modules" |
| 2 |
.SH NAME |
| 3 |
fork, wait, waitpid \- basic process management |
| 4 |
.SH SYNOPSIS |
| 5 |
.ft CW |
| 6 |
@load "fork" |
| 7 |
.sp |
| 8 |
pid = fork() |
| 9 |
.sp |
| 10 |
ret = waitpid(pid) |
| 11 |
.sp |
| 12 |
ret = wait(); |
| 13 |
.ft R |
| 14 |
.SH DESCRIPTION |
| 15 |
The |
| 16 |
.I fork |
| 17 |
extension adds three functions, as follows. |
| 18 |
.TP |
| 19 |
.B fork() |
| 20 |
This function creates a new process. The return value is the zero |
| 21 |
in the child and the process-id number of the child in the parent, |
| 22 |
or \-1 upon error. In the latter case, |
| 23 |
.B ERRNO |
| 24 |
indicates the problem. |
| 25 |
In the child, \fBPROCINFO["pid"]\fP and \fBPROCINFO["ppid"]\fP |
| 26 |
are updated to reflect the correct values. |
| 27 |
.TP |
| 28 |
.B waitpid() |
| 29 |
This function takes a numeric argument, which is the process-id to |
| 30 |
wait for. The return value is that of the |
| 31 |
.IR waitpid (2) |
| 32 |
system call. |
| 33 |
.TP |
| 34 |
.B wait() |
| 35 |
This function waits for the first child to die. |
| 36 |
The return value is that of the |
| 37 |
.IR wait (2) |
| 38 |
system call. |
| 39 |
.\" .SH NOTES |
| 40 |
.SH BUGS |
| 41 |
There is no corresponding |
| 42 |
.B exec() |
| 43 |
function. |
| 44 |
.PP |
| 45 |
The interfaces could be enhanced to provide more facilities, |
| 46 |
including pulling out the various bits of the return status. |
| 47 |
.SH EXAMPLE |
| 48 |
.ft CW |
| 49 |
.nf |
| 50 |
@load "fork" |
| 51 |
\&... |
| 52 |
if ((pid = fork()) == 0) |
| 53 |
print "hello from the child" |
| 54 |
else |
| 55 |
print "hello from the parent" |
| 56 |
.fi |
| 57 |
.ft R |
| 58 |
.SH "SEE ALSO" |
| 59 |
.IR "GAWK: Effective AWK Programming" , |
| 60 |
.IR filefuncs (3am), |
| 61 |
.IR fnmatch (3am), |
| 62 |
.IR inplace (3am), |
| 63 |
.IR ordchr (3am), |
| 64 |
.IR readdir (3am), |
| 65 |
.IR readfile (3am), |
| 66 |
.IR revoutput (3am), |
| 67 |
.IR rwarray (3am), |
| 68 |
.IR time (3am). |
| 69 |
.PP |
| 70 |
.IR fork (2), |
| 71 |
.IR wait (2), |
| 72 |
.IR waitpid (2). |
| 73 |
.SH AUTHOR |
| 74 |
Arnold Robbins, |
| 75 |
.BR [email protected] . |
| 76 |
.SH COPYING PERMISSIONS |
| 77 |
Copyright \(co 2012, 2013, 2018, |
| 78 |
Free Software Foundation, Inc. |
| 79 |
.PP |
| 80 |
Permission is granted to make and distribute verbatim copies of |
| 81 |
this manual page provided the copyright notice and this permission |
| 82 |
notice are preserved on all copies. |
| 83 |
.ig |
| 84 |
Permission is granted to process this file through troff and print the |
| 85 |
results, provided the printed document carries copying permission |
| 86 |
notice identical to this one except for the removal of this paragraph |
| 87 |
(this paragraph not being relevant to the printed manual page). |
| 88 |
.. |
| 89 |
.PP |
| 90 |
Permission is granted to copy and distribute modified versions of this |
| 91 |
manual page under the conditions for verbatim copying, provided that |
| 92 |
the entire resulting derived work is distributed under the terms of a |
| 93 |
permission notice identical to this one. |
| 94 |
.PP |
| 95 |
Permission is granted to copy and distribute translations of this |
| 96 |
manual page into another language, under the above conditions for |
| 97 |
modified versions, except that this permission notice may be stated in |
| 98 |
a translation approved by the Foundation. |
| 99 |
.\" vim: set filetype=nroff : |