RFORK(3)

πŸ“¦ version 0_git20260208, in alpine 3.24, arch rolling, nixos 26.05, nixpkgs unstable

✨ NAME ✨

rfork β€” manipulate process state.

okay bestie, welcome to RFORK(3) from the Library Functions Manual πŸ’… this is the page for rfork, and it’s giving β€œI can rearrange process state and make new processes, but read the fine print first.” 🫢


🌸 SYNOPSIS 🌸

#include <u.h>
#include <libc.h>

int rfork(int flags)

πŸ¦‹ DESCRIPTION πŸ¦‹

So Rfork is a partial implementation of the Plan 9 system call, bestie. It can manipulate some process state and create new processes Γ  la fork(2). It cannot be used to create shared-memory processes β€” that’s Plan 9’s RFMEM flag β€” and if you want that functionality you use proccreate (see thread(3)). πŸ’–

The flags argument to rfork picks which resources of the invoking process (the parent) are shared by the new process (the child), or initialized to their default values. flags is the logical OR of some subset of these:

πŸŽ€ the flags menu πŸŽ€

  • RFPROC β€” if set, a new process is created; otherwise, changes affect the current process. πŸ‘‘
  • RFNOWAIT β€” if set, the child process will be dissociated from the parent. Upon exit the child will leave no Waitmsg (see wait(3)) for the parent to collect. πŸ’€
  • RFNOTEG β€” each process is a member of a group of processes that all receive notes when a note is sent to the group (see postnote(3) and signal(2)). The group of a new process is by default the same as its parent, but if RFNOTEG is set (regardless of RFPROC), the process becomes the first in a new group, isolated from previous processes. In Plan 9, a process can call rfork(RFNOTEG) and then be sure that it will no longer receive console interrupts or other notes. Unix job-control shells put each command in its own process group and then relay notes to the current foreground command, making the idiom less useful. πŸŒ€
  • RFFDG β€” if set, the invoker’s file descriptor table (see intro()) is copied; otherwise the two processes share a single table. πŸŽ€

File descriptors in a shared file descriptor table are kept open until either they are explicitly closed or all processes sharing the table exit. no cap, that’s the rule πŸ“Œ

Now the return-value tea β˜•: if RFPROC is set, the value returned in the parent process is the process id of the child process; the value returned in the child is zero. Without RFPROC, the return value is zero. Process ids range from 1 to the maximum integer (int) value. Rfork will sleep, if necessary, until required process resources are available. 😴

Calling rfork(RFFDG|RFPROC) is equivalent to calling fork(2). periodt πŸ’…


πŸ“ SOURCE πŸ“

/src/lib9/rfork.c


🚨 DIAGNOSTICS 🚨

Rfork sets errstr.


mwah πŸ’‹ this was RFORK(3) from the Library Functions Manual, sourced at /src/lib9/rfork.c β€” the page doesn’t give a date, so we’re not inventing one, bestie 🫢 stay iconic ✨