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.
Remarks
Section titled “Remarks”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.
Caveat
Section titled “Caveat”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.
Caveat
Section titled “Caveat”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).
Example
Section titled “Example”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)}- BinFunction
- ProcFS
- SpawnOpts
- ChildHandle
Properties
Section titled “Properties”abortSignal
Section titled “abortSignal”
readonlyabortSignal: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.
readonlyargv:string[]
Defined in: packages/core/src/kernel/types.ts:1031
Command-line arguments. argv[0] is the command name.
catalogInstall?
Section titled “catalogInstall?”
optionalcatalogInstall?: (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.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Promise<CatalogInstallResult | undefined>
readonlycwd: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.
readonlyfs:ProcFS
Defined in: packages/core/src/kernel/types.ts:1049
Filesystem operations routed through this process’s namespace.
getServer?
Section titled “getServer?”
optionalgetServer?: (name) =>Fileserver|undefined
Defined in: packages/core/src/kernel/types.ts:1189
Retrieve a posted Fileserver from /srv by name.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Fileserver | undefined
readonlypid:Pid
Defined in: packages/core/src/kernel/types.ts:1026
Process identifier for this process.
postServer?
Section titled “postServer?”
optionalpostServer?: (name,server) =>void
Defined in: packages/core/src/kernel/types.ts:1186
Post a Fileserver to /srv for other processes to discover and mount.
Parameters
Section titled “Parameters”string
server
Section titled “server”Returns
Section titled “Returns”void
readonlyppid:Pid
Defined in: packages/core/src/kernel/types.ts:1028
Parent process identifier (0 = kernel-spawned).
registerExec?
Section titled “registerExec?”
optionalregisterExec?: (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.
Parameters
Section titled “Parameters”binName
Section titled “binName”string
Returns
Section titled “Returns”void
registerService?
Section titled “registerService?”
optionalregisterService?: (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).
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Promise<void>
removeServer?
Section titled “removeServer?”
optionalremoveServer?: (name) =>void
Defined in: packages/core/src/kernel/types.ts:1192
Remove a posted Fileserver from /srv.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”void
resolveBin?
Section titled “resolveBin?”
optionalresolveBin?: (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.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Promise<BinFunction | undefined>
shellOpts?
Section titled “shellOpts?”
optionalshellOpts?: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.
stderr
Section titled “stderr”
readonlystderr:Writable
Defined in: packages/core/src/kernel/types.ts:1042
Standard error stream.
readonlystdin:Readable
Defined in: packages/core/src/kernel/types.ts:1038
Standard input stream.
stdout
Section titled “stdout”
readonlystdout:Writable
Defined in: packages/core/src/kernel/types.ts:1040
Standard output stream.
Methods
Section titled “Methods”bind()
Section titled “bind()”bind(
oldPath,newPath,flags?):void
Defined in: packages/core/src/kernel/types.ts:1143
Bind a fileserver-backed subtree from one path onto another.
Parameters
Section titled “Parameters”oldPath
Section titled “oldPath”string
newPath
Section titled “newPath”string
flags?
Section titled “flags?”BindFlags
Returns
Section titled “Returns”void
Invariant
Section titled “Invariant”flags default 'replace'; 'before' prepends to the union
stack (new front), 'after' appends (new back)
chdir()
Section titled “chdir()”chdir(
path):Promise<void>
Defined in: packages/core/src/kernel/types.ts:1126
Change the current working directory.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Promise<void>
Invariant
Section titled “Invariant”Throws ENOTDIR when path is not a directory — validation
happens before cwd is updated, so a failed chdir leaves cwd
unchanged
exec()
Section titled “exec()”exec(
bin,argv):never
Defined in: packages/core/src/kernel/types.ts:1072
Replace the current process image with a new bin. Never returns.
Parameters
Section titled “Parameters”string | BinFunction
string[]
Returns
Section titled “Returns”never
Invariant
Section titled “Invariant”Throws an ExecSentinel the kernel catches — treat as a control-flow primitive; the bin MUST NOT catch it
Invariant
Section titled “Invariant”Same pid, same fds, same namespace; env preserved, argv replaced
exit()
Section titled “exit()”exit(
code?):never
Defined in: packages/core/src/kernel/types.ts:1079
Terminate the current process with an exit code. Never returns.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”never
Invariant
Section titled “Invariant”Throws an ExitError the kernel catches; code after proc.exit()
never runs even under try/finally that swallows the error
getTermSize()?
Section titled “getTermSize()?”
optionalgetTermSize():TerminalSize
Defined in: packages/core/src/kernel/types.ts:1201
Return current terminal dimensions, if a controlling terminal exists.
Returns
Section titled “Returns”mount()
Section titled “mount()”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.
Parameters
Section titled “Parameters”server
Section titled “server”string
Returns
Section titled “Returns”void
Invariant
Section titled “Invariant”Mutates only the calling process’s namespace — siblings and already-spawned children do NOT see the mount (snapshot-on-fork)
Invariant
Section titled “Invariant”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.
Parameters
Section titled “Parameters”signal
Section titled “signal”Returns
Section titled “Returns”void
on(
signal,handler):void
Defined in: packages/core/src/kernel/types.ts:1153
Register a handler for a signal.
Parameters
Section titled “Parameters”signal
Section titled “signal”handler
Section titled “handler”() => void
Returns
Section titled “Returns”void
Invariant
Section titled “Invariant”Per-process, one handler per signal — re-registering replaces
Invariant
Section titled “Invariant”Fires synchronously during signal() delivery; uncaught handler
exceptions propagate to the signaler’s call site
resolveServer()
Section titled “resolveServer()”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).
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Fileserver | undefined
setsid()
Section titled “setsid()”setsid():
Pid
Defined in: packages/core/src/kernel/types.ts:1118
Create a new session, making this process the session leader.
Returns
Section titled “Returns”Invariant
Section titled “Invariant”Returns the new sid which equals this process’s pid
setuid()
Section titled “setuid()”setuid(
uid):void
Defined in: packages/core/src/kernel/types.ts:1112
Change the process’s uid and euid. Restricted to uid=0.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”void
Invariant
Section titled “Invariant”Throws EPERM for non-root callers — no capability mask or
setuid-bit emulation at this layer
signal()
Section titled “signal()”signal(
pid,sig):void
Defined in: packages/core/src/kernel/types.ts:1087
Send a signal to another process.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”void
Invariant
Section titled “Invariant”Fires synchronously — target’s abort signal is set and any
registered handler invoked before signal() returns
Invariant
Section titled “Invariant”Silently no-op when pid is not live (no ESRCH at this layer)
spawn()
Section titled “spawn()”spawn(
bin,argv,opts?):Promise<ChildHandle>
Defined in: packages/core/src/kernel/types.ts:1064
Spawn a child process.
Parameters
Section titled “Parameters”string | BinFunction
A BinFunction or string path resolved via $PATH.
string[]
Arguments for the child. argv[0] is conventionally the command name.
Optional I/O redirects, env overrides, cwd.
Returns
Section titled “Returns”Promise<ChildHandle>
A ChildHandle with the child’s pid and I/O streams.
Invariant
Section titled “Invariant”Child inherits parent’s uid/gid/sid/pgid unless overridden
Invariant
Section titled “Invariant”Numeric stdin/stdout/stderr in opts refer to the PARENT’S fd
table (dup semantics); stream objects are taken as-is
Invariant
Section titled “Invariant”opts.env is MERGED into the parent’s env, not replacement
unmount()
Section titled “unmount()”unmount(
path):void
Defined in: packages/core/src/kernel/types.ts:1198
Remove a mount point from this process’s namespace.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”void
wait()
Section titled “wait()”wait(
pid):Promise<ExitCode>
Defined in: packages/core/src/kernel/types.ts:1095
Await the exit of a specific child.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Promise<ExitCode>
Invariant
Section titled “Invariant”Rejects with ProcError('ESRCH') if the pid is not (or no longer) live
Invariant
Section titled “Invariant”Safe to call after the child has zombied — the exit code is held until the parent reaps it here
waitAny()
Section titled “waitAny()”Defined in: packages/core/src/kernel/types.ts:1103
Await any child’s exit.
Returns
Section titled “Returns”Promise<{ code: ExitCode; pid: Pid; }>
Invariant
Section titled “Invariant”Rejects with ProcError('ECHILD') when the caller has no
remaining children — init’s supervision loop uses this to detect
“all children reaped”