Skip to content

ProcContext

Defined in: packages/core/src/kernel/types.ts:1024

The system-call surface available to every bin. Every running process receives a ProcContext.

Consumed by bin functions — the kernel builds one at spawn time and passes it to the bin. Not an interface user code implements.

Single API surface for process identity, I/O streams, filesystem (ProcFS), lifecycle control (spawn/exec/exit/signal/wait), namespace manipulation, and optional capabilities (catalogInstall?, registerExec?, registerService?, srv posting). Optional members are present only when the system was built with the corresponding capability; bins MUST check for existence before calling.

Lifecycle: valid for the duration of the bin’s execution. After the bin returns or throws, the kernel reaps the process and the context becomes inert.

Streams are wrapped with zombie/abort guards — once the process is a zombie or its abort signal fires, reads return empty and writes return 0. A bin polling proc.stdin after proc.exit() sees EOF, not an error.

env is a mutable reference. Mutations propagate to children spawned AFTER the mutation, not to already-running children (each child snapshots its env on spawn).

import { exitCode, type BinFunction } from '@fishnet/core'
const myBin: BinFunction = async (proc) => {
await proc.stdout.write(`hi ${proc.argv[1] ?? 'world'}\n`)
return exitCode(0)
}

readonly abortSignal: AbortSignal

Defined in: packages/core/src/kernel/types.ts:1046

Abort signal — aborted when the process is killed. Bins can check abortSignal.aborted or pass it to fetch/AbortController-aware APIs.


readonly argv: string[]

Defined in: packages/core/src/kernel/types.ts:1031

Command-line arguments. argv[0] is the command name.


optional catalogInstall?: (name) => Promise<CatalogInstallResult | undefined>

Defined in: packages/core/src/kernel/types.ts:1162

Install a package from the pre-bundled catalog. Present only when the system was built with .catalog() entries. Returns install info or undefined if the package is not in the catalog.

string

Promise<CatalogInstallResult | undefined>


readonly cwd: AbsPath

Defined in: packages/core/src/kernel/types.ts:1035

Current working directory (absolute path).


env: Record<string, string>

Defined in: packages/core/src/kernel/types.ts:1033

Environment variables. Mutable — changes are visible to child processes.


readonly fs: ProcFS

Defined in: packages/core/src/kernel/types.ts:1049

Filesystem operations routed through this process’s namespace.


optional getServer?: (name) => Fileserver | undefined

Defined in: packages/core/src/kernel/types.ts:1189

Retrieve a posted Fileserver from /srv by name.

string

Fileserver | undefined


readonly pid: Pid

Defined in: packages/core/src/kernel/types.ts:1026

Process identifier for this process.


optional postServer?: (name, server) => void

Defined in: packages/core/src/kernel/types.ts:1186

Post a Fileserver to /srv for other processes to discover and mount.

string

Fileserver

void


readonly ppid: Pid

Defined in: packages/core/src/kernel/types.ts:1028

Parent process identifier (0 = kernel-spawned).


optional registerExec?: (binName, fn) => void

Defined in: packages/core/src/kernel/types.ts:1168

Register a bin function on the filesystem exec table. Present when the system supports runtime package installation.

string

BinFunction

void


optional registerService?: (def) => Promise<void>

Defined in: packages/core/src/kernel/types.ts:1176

Register and start a service at runtime (post-boot). Present when init is running with a supervisor. Validates bin is resolvable before registering. Services go through existing supervisor machinery (restart policies, backoff).

ServiceDef

Promise<void>


optional removeServer?: (name) => void

Defined in: packages/core/src/kernel/types.ts:1192

Remove a posted Fileserver from /srv.

string

void


optional resolveBin?: (name) => Promise<BinFunction | undefined>

Defined in: packages/core/src/kernel/types.ts:1183

Resolve a bin name to a BinFunction via the kernel’s exec resolution (namespace/ExecCapable/$PATH lookup). Used by the shell to discover promoted builtins (e.g. pkg) at runtime without a static import.

string

Promise<BinFunction | undefined>


optional shellOpts?: ShellOpts

Defined in: packages/core/src/kernel/types.ts:1207

Shell option flags (e.g. xtrace). Present when the process is running inside a shell interpreter; undefined in non-shell contexts.


readonly stderr: Writable

Defined in: packages/core/src/kernel/types.ts:1042

Standard error stream.


readonly stdin: Readable

Defined in: packages/core/src/kernel/types.ts:1038

Standard input stream.


readonly stdout: Writable

Defined in: packages/core/src/kernel/types.ts:1040

Standard output stream.

bind(oldPath, newPath, flags?): void

Defined in: packages/core/src/kernel/types.ts:1143

Bind a fileserver-backed subtree from one path onto another.

string

string

BindFlags

void

flags default 'replace'; 'before' prepends to the union stack (new front), 'after' appends (new back)


chdir(path): Promise<void>

Defined in: packages/core/src/kernel/types.ts:1126

Change the current working directory.

string

Promise<void>

Throws ENOTDIR when path is not a directory — validation happens before cwd is updated, so a failed chdir leaves cwd unchanged


exec(bin, argv): never

Defined in: packages/core/src/kernel/types.ts:1072

Replace the current process image with a new bin. Never returns.

string | BinFunction

string[]

never

Throws an ExecSentinel the kernel catches — treat as a control-flow primitive; the bin MUST NOT catch it

Same pid, same fds, same namespace; env preserved, argv replaced


exit(code?): never

Defined in: packages/core/src/kernel/types.ts:1079

Terminate the current process with an exit code. Never returns.

ExitCode

never

Throws an ExitError the kernel catches; code after proc.exit() never runs even under try/finally that swallows the error


optional getTermSize(): TerminalSize

Defined in: packages/core/src/kernel/types.ts:1201

Return current terminal dimensions, if a controlling terminal exists.

TerminalSize


mount(server, path): void

Defined in: packages/core/src/kernel/types.ts:1136

Mount a Fileserver at an absolute path in THIS process’s namespace.

Fileserver

string

void

Mutates only the calling process’s namespace — siblings and already-spawned children do NOT see the mount (snapshot-on-fork)

Replaces any existing mount at path; use bind() for union stacks


off(signal): void

Defined in: packages/core/src/kernel/types.ts:1155

Remove any handler for signal. No-op if none was registered.

Signal

void


on(signal, handler): void

Defined in: packages/core/src/kernel/types.ts:1153

Register a handler for a signal.

Signal

() => void

void

Per-process, one handler per signal — re-registering replaces

Fires synchronously during signal() delivery; uncaught handler exceptions propagate to the signaler’s call site


resolveServer(path): Fileserver | undefined

Defined in: packages/core/src/kernel/types.ts:1195

Resolve a path to the Fileserver mounted at that point (for post/srv).

string

Fileserver | undefined


setsid(): Pid

Defined in: packages/core/src/kernel/types.ts:1118

Create a new session, making this process the session leader.

Pid

Returns the new sid which equals this process’s pid


setuid(uid): void

Defined in: packages/core/src/kernel/types.ts:1112

Change the process’s uid and euid. Restricted to uid=0.

Uid

void

Throws EPERM for non-root callers — no capability mask or setuid-bit emulation at this layer


signal(pid, sig): void

Defined in: packages/core/src/kernel/types.ts:1087

Send a signal to another process.

Pid

Signal

void

Fires synchronously — target’s abort signal is set and any registered handler invoked before signal() returns

Silently no-op when pid is not live (no ESRCH at this layer)


spawn(bin, argv, opts?): Promise<ChildHandle>

Defined in: packages/core/src/kernel/types.ts:1064

Spawn a child process.

string | BinFunction

A BinFunction or string path resolved via $PATH.

string[]

Arguments for the child. argv[0] is conventionally the command name.

SpawnOpts

Optional I/O redirects, env overrides, cwd.

Promise<ChildHandle>

A ChildHandle with the child’s pid and I/O streams.

Child inherits parent’s uid/gid/sid/pgid unless overridden

Numeric stdin/stdout/stderr in opts refer to the PARENT’S fd table (dup semantics); stream objects are taken as-is

opts.env is MERGED into the parent’s env, not replacement


unmount(path): void

Defined in: packages/core/src/kernel/types.ts:1198

Remove a mount point from this process’s namespace.

string

void


wait(pid): Promise<ExitCode>

Defined in: packages/core/src/kernel/types.ts:1095

Await the exit of a specific child.

Pid

Promise<ExitCode>

Rejects with ProcError('ESRCH') if the pid is not (or no longer) live

Safe to call after the child has zombied — the exit code is held until the parent reaps it here


waitAny(): Promise<{ code: ExitCode; pid: Pid; }>

Defined in: packages/core/src/kernel/types.ts:1103

Await any child’s exit.

Promise<{ code: ExitCode; pid: Pid; }>

Rejects with ProcError('ECHILD') when the caller has no remaining children — init’s supervision loop uses this to detect “all children reaped”