FORK1(9)
β¨ NAME β¨
fork1 β create a new process
okay bestie, welcome to fork1(9) from the Kernel Developer's Manual π this one is literally about making new processes, and it's giving main-character backend energy fr fr.
πΈ SYNOPSIS πΈ
#include <sys/types.h>
#include <sys/proc.h>
int
fork1(struct lwp *l1, int flags, int exitsig, void *stack,
size_t stacksize, void (*func)(void *), void *arg,
register_t *retval);
π¦ DESCRIPTION π¦
fork1() creates a new process out of the process behind l1, and l1 is assumed to be the current lwp. It's used primarily to implement the fork(2) and vfork(2) system calls, but it's lowkey versatile enough to be a backend for stuff like the __clone(2) call too π
The flags argument controls the semantics of the fork operation, and it's made up of the bitwise-OR of these values:
FORK_PPWAITβ the parent process will sleep until the child process successfully callsexecve(2)or exits, either by a call to_exit(2)or abnormally π΄FORK_SHAREVMβ the child process will share the parent's virtual address space. If this flag is not specified, the child gets a copy-on-write snapshot of the parent's address space π«ΆFORK_SHARECWDβ the child process will share the parent's current directory, root directory, and file creation mask.FORK_SHAREFILESβ the child process will share the parent's file descriptors.FORK_SHARESIGSβ the child process will share the parent's signal actions.FORK_NOWAITβ the child process will at creation time be inherited by the init process.FORK_CLEANFILESβ the child process will not copy or share the parent's descriptors, but rather will start out with a clean set.
A flags value of 0 indicates a standard fork operation, no cap.
The exitsig argument controls the signal sent to the parent on child death. If normal operation is desired, SIGCHLD should be supplied.
It is possible to specify the child userspace stack location and size by using the stack and stacksize arguments, respectively. Values NULL and 0, respectively, will give the child the default values for the machine architecture in question.
The arguments func and arg can be used to specify a kernel function to be called when the child process returns instead of child_return(). These are used for example in starting the init process and creating kernel threads π§
The retval argument is provided for the use of system call stubs. If retval is not NULL, it will hold the following values after successful completion of the fork operation:
retval[0]β this will contain the pid of the child process.retval[1]β in the parent process, this will contain the value0. In the child process, this will contain1.
User level system call stubs typically subtract 1 from retval[1] and bitwise-AND it with retval[0], thus returning the pid to the parent process and 0 to the child. slay, that's the whole trick π
π RETURN VALUES π
Upon successful completion of the fork operation, fork1() returns 0. Otherwise, the following error values are returned:
[EAGAIN]β the limit on the total number of system processes would be exceeded; or the limitRLIMIT_NPROCon the total number of processes under execution by this user id would be exceeded π
π SEE ALSO π
xoxo, your Debian source/version page, dated April 16, 2018 β FORK1(9) says bye bestie π
π
π¦ where this page comes from
- nixpkgs unstable: netbsd-source 11.0
- Copyright (c) 1998 The NetBSD Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms