Extension Sample Fork (The GNU Awk User’s Guide)
17.7.3 Interface to fork(), wait(), and waitpid()
fork extension adds three functions, as follows:
This is how you load the extension.
pid = fork()
This function creates a new process. The return value is zero in the child and the process ID number of the child in the parent, or -1 upon error. In the latter case,
ERRNOindicates the problem. In the child,
PROCINFO["ppid"]are updated to reflect the correct values.
ret = waitpid(pid)
This function takes a numeric argument, which is the process ID to wait for. The return value is that of the
ret = wait()
This function waits for the first child to die. The return value is that of the
There is no corresponding
Here is an example:
@load "fork" … if ((pid = fork()) == 0) print "hello from the child" else print "hello from the parent"