Process Creation and Replacement

Choose the creation operation according to what the child must share and what must happen before its program starts. Keep kernel behavior distinct from C library facilities such as posix_spawn and fexecve.

Fork inheritance #

fork() creates a separate process with one thread: the thread that called it. Other parent threads are absent from the child. Ordinary private memory uses copy-on-write; mappings explicitly shared before the fork remain shared. A multithreaded parent's child can inherit library locks whose owners do not exist after the fork. Its pre-exec work must respect the runtime's fork contract.

The child inherits these resources or settings:

ResourceChild behavior
File descriptorsSeparate descriptor table; entries refer to the same open file descriptions, sharing offsets and status flags
Open-file-description and flock locksRetained through the shared open file descriptions
Directory streams and message-queue descriptorsCopied runtime state or descriptors; directory-stream position sharing depends on the runtime
Signal dispositions and maskCopied; pending signals start empty
Filesystem contextCurrent directory, root directory, and umask copied
Limits and timer slackInherited
Peios primary tokenIndependently duplicated; the parent's active impersonation is not inherited
Process security stateSubject to the kernel's PSB and protection inheritance rules

The child receives a new PID and Process GUID. Resource-usage counters start at zero. It does not inherit memory locks, semaphore adjustments, POSIX process-associated record locks, POSIX timers, interval timers, asynchronous I/O operations or directory-change notifications. On x86, the child inherits the I/O-permission bitmap when one is present. The parent-death signal setting is reset. MADV_DONTFORK mappings are absent; MADV_WIPEONFORK mappings are zeroed in the child.

The normal child termination signal is SIGCHLD. The distinction between an independent token on fork and a shared primary token for CLONE_THREAD is defined by token lifecycle. Later token mutations must not be inferred to affect both processes.

Vfork and create-then-replace #

vfork() suspends the calling thread while the child shares its address space until exec or exit. It does not freeze every other thread in a multithreaded parent. The child must not return from the calling function or perform arbitrary work in that shared runtime state. Follow the C runtime's restrictions and proceed directly to an exec operation or _exit.

posix_spawn() is a C library interface for creating a process and executing a program, with declared file actions and attributes. Use it when those controls express the launch operation. Its implementation and supported attributes belong to the selected runtime, not to a separate Peios syscall.

Clone arguments #

clone exposes task-sharing choices. Its raw syscall argument order can be architecture-specific; a C wrapper that takes a start function is a different interface. clone3 uses a size-versioned argument structure:

MemberPurpose
flagsSharing and creation choices
pidfdDestination for a returned pidfd
child_tid, parent_tidAddresses for thread-ID bookkeeping
exit_signalSignal delivered when the child terminates
stack, stack_sizeChild stack region
tlsArchitecture-specific thread-local-storage value
set_tid, set_tid_sizeRequested task identifiers, subject to privilege checks
cgroupTarget cgroup for CLONE_INTO_CGROUP

Pass the structure size supported by the caller. Unknown trailing fields must be zero. Requests for specific task IDs are privileged; Peios applies its KACS capability mapping rather than granting authority from UID 0.

Clone flags #

Flags select sharing and bookkeeping:

FlagEffect
CLONE_VMShare the address space
CLONE_FSShare current directory, root directory, and umask
CLONE_FILESShare the descriptor table itself
CLONE_SIGHANDShare signal dispositions; requires CLONE_VM
CLONE_THREADJoin the thread group; requires CLONE_SIGHAND
CLONE_SETTLSSet the child TLS value
CLONE_SYSVSEMShare the System V semaphore-adjustment list
CLONE_IOShare the I/O context where the I/O scheduler uses it
CLONE_PIDFDReturn a pidfd identifying the created task
CLONE_PARENTUse the caller's parent; prohibited for an init process
CLONE_PARENT_SETTID, CLONE_CHILD_SETTIDStore the new TID in the specified address space
CLONE_CHILD_CLEARTIDArrange exit-time clearing and futex notification
CLONE_UNTRACEDPrevent a tracer from forcing CLONE_PTRACE on this child
CLONE_VFORKSuspend the caller until the child releases the shared address space

A conventional thread uses shared memory, filesystem context, descriptors, signal dispositions, and a thread group, with TLS and TID bookkeeping. Threads share getpid() and signal actions but have individual signal masks. Ordinary CLONE_THREAD termination is not collected through the process wait interface; the process's parent collects the thread group's termination.

The CLONE_NEW* flags select namespace separation. In Peios, private mount namespaces have their own KACS object model; the other namespace operations must satisfy their privilege checks. See the namespace contract rather than treating all flags as available to an ordinary caller. CLONE_INTO_CGROUP has separate target-cgroup rules. CLONE_DETACHED has no general detached-thread meaning; incompatible combinations, including with CLONE_PIDFD, can be rejected.

Replace the executable #

execve selects a pathname. execveat can select relative to a directory file descriptor or use AT_EMPTY_PATH with a file descriptor directly. AT_SYMLINK_NOFOLLOW refuses a final symbolic link. fexecve is the C library interface for descriptor-based execution; its mechanism depends on the runtime.

A successful exec preserves the process identity while replacing the program:

PreservedReplaced or reset
PID, parent PID, Process GUID, process group, session, and controlling terminalProgram mappings, stack, heap, and memory locks
Descriptors without close-on-execDescriptors marked close-on-exec
Current directory, root directory, umask, and resource limitsOther threads in the group
Signal mask, pending signals, and ignored dispositionsCaught-signal handlers and alternate signal stack
Primary token, subject to the Peios exec rulesActive impersonation, reverted before the new program starts

Exec also discards attached System V shared memory, POSIX shared-memory mappings, POSIX message-queue descriptors, named semaphore references, POSIX timers, outstanding asynchronous I/O, registered exit handlers, directory streams, and runtime synchronization state. The floating-point environment is reset and the process name follows the new executable.

NEW_PROCESS_MIN can lower token integrity according to the executable's explicit label. Execution trust, process protection, and PSB rules apply separately. Set-user-ID bits do not provide the upstream identity transition. Read the detailed token rules before claiming identity survives unchanged.

Stable process handles #

A pidfd refers to a particular task instance, avoiding later PID reuse:

OperationPurpose
pidfd_openOpen a handle for an existing task
pidfd_send_signalSend a signal through that stable handle
pidfd_getfdDuplicate a target task's descriptor into the caller

Opening by PID still requires obtaining the intended PID safely. A pidfd does not waive signaling or cross-process descriptor access checks. KACS applies the target process's access rules to the corresponding operation.

Edit this page