FORK(3am)
π FORK(3am) β GNU Awk Extension Modules π
okay bestie, buckle up, we're doing process management today and it's gonna be so good. this is the fork page from the gawk extension modules family, and honestly? it's giving tiny-but-mighty. π¦
β¨ NAME β¨
fork, wait, waitpid β basic process management, aka making new little processes and then politely waiting for them to be done π
β¨ SYNOPSIS β¨
@load "fork"
pid = fork()
ret = waitpid(pid)
ret = wait();
no cap, that's the whole vibe. three functions, three lines, we love a minimal queen. π
β¨ DESCRIPTION β¨
so the fork extension adds three functions, as follows. and yes i'm listing all of them, because every single one matters, periodt.
fork()β this function creates a new process. the return value is the zero in the child and the process-id number of the child in the parent, or-1upon error. in the latter case,ERRNOindicates the problem. In the child,PROCINFO["pid"]andPROCINFO["ppid"]are updated to reflect the correct values. π«Άwaitpid()β this function takes a numeric argument, which is the process-id to wait for. the return value is that of thewaitpid(2)system call.wait()β this function waits for the first child to die. the return value is that of thewait(2)system call. π rip little buddy
fr fr, that-1on error is the moment you checkERRNO. don't skip it. π
β¨ BUGS β¨
not me being the bearer of bad news but:
- there is no corresponding
exec()function. π - the interfaces could be enhanced to provide more facilities, including pulling out the various bits of the return status. (so like, it's a little limited, bestie, we're working with what we've got.)
β¨ EXAMPLE β¨
here's the moment you've been waiting for, the group chat screenshot of code:
@load "fork"
...
if ((pid = fork()) == 0)
print "hello from the child"
else
print "hello from the parent"
see how the child goes one way and the parent goes the other? that's the whole fork() thing. main character energy for both branches. π
β¨ SEE ALSO β¨
go read these next, i promise they're worth it:
GAWK: Effective AWK Programming, and the man pages for the other extensions shipped with gawk. πfork(2),wait(2),waitpid(2).
β¨ AUTHOR β¨
Arnold Robbins, arnold@skeeve.com. (ty arnold, iconic of you π)
β¨ COPYING PERMISSIONS β¨
Copyright Β© 2012, 2013, 2018, 2026, Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of this manual page provided the copyright notice and this permission notice are preserved on all copies.
Permission is granted to copy and distribute modified versions of this manual page under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.
Permission is granted to copy and distribute translations of this manual page into another language, under the above conditions for modified versions, except that this permission notice may be stated in a translation approved by the Foundation.
okay that's the whole page bestie, you ate it π β¨ this was the FORK(3am) page from the GNU Awk Extension Modules, brought to you by the Free Software Foundation, dated Feb 25 2026. go fork something (responsibly). π¦π
π¦ where this page comes from
- arch rolling: gawk 5.4.1-1 Β· GPL-3.0-or-later
- nixos 26.05: gawk-interactive 5.4.1
- nixpkgs unstable: gawk 5.4.1
- nixpkgs unstable: gawk-interactive 5.4.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms