gawk: Extension Sample Fork

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