Skip to main content

Process Lifecycle

These syscalls control process creation, execution, and termination.

sys_clone

Create a new process or thread with fine-grained control over resource sharing.
dword_t sys_clone(dword_t flags, addr_t stack, addr_t ptid, addr_t tls, addr_t ctid)
flags
dword_t
Bitmask controlling what resources are shared between parent and child:
  • CLONE_VM (0x100): Share memory space
  • CLONE_FS (0x200): Share filesystem information
  • CLONE_FILES (0x400): Share file descriptor table
  • CLONE_SIGHAND (0x800): Share signal handlers
  • CLONE_THREAD (0x10000): Create thread in same thread group
  • CLONE_VFORK (0x4000): Suspend parent until child exits or execs
  • CLONE_SETTLS (0x80000): Set thread-local storage
  • CLONE_PARENT_SETTID (0x100000): Store child TID at ptid
  • CLONE_CHILD_CLEARTID (0x200000): Clear and futex-wake ctid on exit
stack
addr_t
Stack pointer for new process/thread. If 0, uses parent’s stack.
ptid
addr_t
Address to store parent TID (when CLONE_PARENT_SETTID is set).
tls
addr_t
Thread-local storage descriptor (when CLONE_SETTLS is set).
ctid
addr_t
Address for child TID operations (CLONE_CHILD_SETTID/CLEARTID).
return
dword_t
On success, returns child process ID in parent, 0 in child. On error, returns negative errno.
Error Codes:
  • ENOMEM (-12): Insufficient memory
  • EINVAL (-22): Invalid flags combination
Source: kernel/fork.c:56

sys_fork

Create a child process with copy-on-write memory.
dword_t sys_fork(void)
return
dword_t
Returns child PID in parent process, 0 in child process. On error, returns negative errno.
Description: Creates a complete copy of the calling process with separate memory space (copy-on-write), file descriptors, and signal handlers. Source: kernel/fork.c

sys_vfork

Create a child process that shares memory with parent until exec.
dword_t sys_vfork(void)
return
dword_t
Returns child PID in parent, 0 in child. On error, returns negative errno.
Description: Similar to fork but suspends parent until child calls execve or exits. Child runs in parent’s memory space. Source: kernel/fork.c

sys_execve

Replace current process image with a new program.
dword_t sys_execve(addr_t file, addr_t argv, addr_t envp)
file
addr_t
Address of null-terminated path to executable file.
argv
addr_t
Address of array of argument string pointers, terminated by NULL.
envp
addr_t
Address of array of environment string pointers, terminated by NULL.
return
dword_t
Does not return on success. On error, returns negative errno.
Error Codes:
  • ENOENT (-2): File not found
  • EACCES (-13): Permission denied
  • ENOEXEC (-8): Invalid executable format
  • E2BIG (-7): Argument list too long
  • EFAULT (-14): Bad address
Source: kernel/exec.c:38

sys_exit

Terminate the calling thread.
dword_t sys_exit(dword_t status)
status
dword_t
Exit status code to return to parent process.
return
dword_t
Does not return.
Description: Terminates the calling thread and releases its resources. Exit status is made available to parent via wait. Source: kernel/exit.c:44

sys_exit_group

Terminate all threads in the calling process.
dword_t sys_exit_group(dword_t status)
status
dword_t
Exit status for the entire process group.
return
dword_t
Does not return.
Description: Terminates all threads in the process and returns the exit status to the parent. Source: kernel/exit.c:42

Process Waiting

Syscalls for waiting on child process state changes.

sys_wait4

Wait for process state change and collect resource usage.
dword_t sys_wait4(pid_t_ pid, addr_t status_addr, dword_t options, addr_t rusage_addr)
pid
pid_t_
Process ID to wait for:
  • < -1: Wait for any child in process group |pid|
  • -1: Wait for any child process
  • 0: Wait for any child in same process group
  • > 0: Wait for specific child with this PID
status_addr
addr_t
Address to store exit status. Can be 0 to ignore.
options
dword_t
Wait options:
  • WNOHANG: Return immediately if no child has exited
  • WUNTRACED: Also return for stopped children
  • WCONTINUED: Also return for continued children
rusage_addr
addr_t
Address to store resource usage information. Can be 0 to ignore.
return
dword_t
Returns PID of child that changed state, 0 if WNOHANG and no change, or negative errno on error.
Error Codes:
  • ECHILD (-10): No child processes
  • EINVAL (-22): Invalid options
  • EINTR (-4): Interrupted by signal
Source: kernel/calls.h:44

sys_waitid

Wait for process state change with extended information.
dword_t sys_waitid(int_t idtype, pid_t_ id, addr_t info_addr, int_t options)
idtype
int_t
Type of ID:
  • P_PID: Wait for specific process
  • P_PGID: Wait for any process in process group
  • P_ALL: Wait for any child (id ignored)
id
pid_t_
Process or process group ID to wait for.
info_addr
addr_t
Address to store siginfo_t structure with detailed information.
options
int_t
Same options as wait4.
return
dword_t
Returns 0 on success, negative errno on error.
Source: kernel/calls.h:45

sys_waitpid

Simplified wait for specific process.
dword_t sys_waitpid(pid_t_ pid, addr_t status_addr, dword_t options)
pid
pid_t_
Process ID to wait for (same semantics as wait4).
status_addr
addr_t
Address to store exit status.
options
dword_t
Wait options (same as wait4).
return
dword_t
Returns PID of child that changed state or negative errno.
Source: kernel/calls.h:46

Process Identification

Syscalls for querying process and group IDs.

sys_getpid

Get process ID.
pid_t_ sys_getpid(void)
return
pid_t_
Returns the process ID of the calling process. Always succeeds.
Source: kernel/calls.h:201

sys_gettid

Get thread ID.
pid_t_ sys_gettid(void)
return
pid_t_
Returns the thread ID of the calling thread. Always succeeds.
Source: kernel/calls.h:202

sys_getppid

Get parent process ID.
pid_t_ sys_getppid(void)
return
pid_t_
Returns the process ID of the parent process. Always succeeds.
Source: kernel/calls.h:203

sys_getpgid

Get process group ID.
pid_t_ sys_getpgid(pid_t_ pid)
pid
pid_t_
Process ID to query. 0 means calling process.
return
pid_t_
Returns process group ID on success, negative errno on error.
Source: kernel/calls.h:204

sys_setpgid

Set process group ID.
dword_t sys_setpgid(pid_t_ pid, pid_t_ pgid)
pid
pid_t_
Process ID to modify. 0 means calling process.
pgid
pid_t_
New process group ID. 0 means use pid as pgid.
return
dword_t
Returns 0 on success, negative errno on error.
Source: kernel/calls.h:205

Build docs developers (and LLMs) love