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.Bitmask controlling what resources are shared between parent and child:
CLONE_VM(0x100): Share memory spaceCLONE_FS(0x200): Share filesystem informationCLONE_FILES(0x400): Share file descriptor tableCLONE_SIGHAND(0x800): Share signal handlersCLONE_THREAD(0x10000): Create thread in same thread groupCLONE_VFORK(0x4000): Suspend parent until child exits or execsCLONE_SETTLS(0x80000): Set thread-local storageCLONE_PARENT_SETTID(0x100000): Store child TID at ptidCLONE_CHILD_CLEARTID(0x200000): Clear and futex-wake ctid on exit
Stack pointer for new process/thread. If 0, uses parent’s stack.
Address to store parent TID (when CLONE_PARENT_SETTID is set).
Thread-local storage descriptor (when CLONE_SETTLS is set).
Address for child TID operations (CLONE_CHILD_SETTID/CLEARTID).
On success, returns child process ID in parent, 0 in child. On error, returns negative errno.
ENOMEM(-12): Insufficient memoryEINVAL(-22): Invalid flags combination
sys_fork
Create a child process with copy-on-write memory.Returns child PID in parent process, 0 in child process. On error, returns negative errno.
sys_vfork
Create a child process that shares memory with parent until exec.Returns child PID in parent, 0 in child. On error, returns negative errno.
sys_execve
Replace current process image with a new program.Address of null-terminated path to executable file.
Address of array of argument string pointers, terminated by NULL.
Address of array of environment string pointers, terminated by NULL.
Does not return on success. On error, returns negative errno.
ENOENT(-2): File not foundEACCES(-13): Permission deniedENOEXEC(-8): Invalid executable formatE2BIG(-7): Argument list too longEFAULT(-14): Bad address
sys_exit
Terminate the calling thread.Exit status code to return to parent process.
Does not return.
sys_exit_group
Terminate all threads in the calling process.Exit status for the entire process group.
Does not return.
Process Waiting
Syscalls for waiting on child process state changes.sys_wait4
Wait for process state change and collect resource usage.Process ID to wait for:
< -1: Wait for any child in process group |pid|-1: Wait for any child process0: Wait for any child in same process group> 0: Wait for specific child with this PID
Address to store exit status. Can be 0 to ignore.
Wait options:
WNOHANG: Return immediately if no child has exitedWUNTRACED: Also return for stopped childrenWCONTINUED: Also return for continued children
Address to store resource usage information. Can be 0 to ignore.
Returns PID of child that changed state, 0 if WNOHANG and no change, or negative errno on error.
ECHILD(-10): No child processesEINVAL(-22): Invalid optionsEINTR(-4): Interrupted by signal
sys_waitid
Wait for process state change with extended information.Type of ID:
P_PID: Wait for specific processP_PGID: Wait for any process in process groupP_ALL: Wait for any child (id ignored)
Process or process group ID to wait for.
Address to store siginfo_t structure with detailed information.
Same options as wait4.
Returns 0 on success, negative errno on error.
sys_waitpid
Simplified wait for specific process.Process ID to wait for (same semantics as wait4).
Address to store exit status.
Wait options (same as wait4).
Returns PID of child that changed state or negative errno.
Process Identification
Syscalls for querying process and group IDs.sys_getpid
Get process ID.Returns the process ID of the calling process. Always succeeds.
sys_gettid
Get thread ID.Returns the thread ID of the calling thread. Always succeeds.
sys_getppid
Get parent process ID.Returns the process ID of the parent process. Always succeeds.
sys_getpgid
Get process group ID.Process ID to query. 0 means calling process.
Returns process group ID on success, negative errno on error.
sys_setpgid
Set process group ID.Process ID to modify. 0 means calling process.
New process group ID. 0 means use pid as pgid.
Returns 0 on success, negative errno on error.