fork, wait, waitpid โ ๐งต basic process management
| Use Case | Command | Description |
|---|---|---|
| ๐ถ Create a child process | fork() | Returns 0 in child, PID in parent, or -1 on error |
| โณ Wait for a specific child | waitpid(pid) | Waits for process with given PID to finish |
| โณ Wait for any child | wait() | Waits for the first child process to terminate |
@load "fork"
pid = fork()
ret = waitpid(pid)
ret = wait();
The fork extension adds three functions, as follows.
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, ERRNO indicates the problem. In the child, PROCINFO["pid"] and PROCINFO["ppid"] are updated to reflect the correct values.
This function takes a numeric argument, which is the process-id to wait for. The return value is that of the waitpid(2) system call.
This function waits for the first child to die. The return value is that of the wait(2) system call.
@load "fork"
...
if ((pid = fork()) == 0)
print "hello from the child"
else
print "hello from the parent"
Arnold Robbins, arnold@skeeve.com.
Copyright ยฉ 2012, 2013, 2018, Free Software Foundation, Inc.
Free Software Foundation ยท Feb 02 2018 ยท FORK(3am)
Generated by phpman v4.10.0-7-g98e9fd5 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-09-15 19:28 @216.73.216.233
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)