js/internal/process/spawn

js/internal/process/spawn.ts

Shared POSIX child-process mechanics.

This module owns the error-prone, policy-neutral parts of launching and observing children: C-string lifetimes, spawn actions and attributes, signal disposition, cwd/environment handling, and asynchronous reaping. Callers provide only their descriptor wiring and lifecycle policy.

Useful references:

Interfaces

interface SpawnActions {

Methods

open(targetFd: number, path: string, flags: number, mode?: number): void
dup2(fd: number, targetFd: number): void
close(fd: number): void
closeIfNeeded(fd: number, targetFd: number): void
closeFrom(fd: number): boolean
inherit(fd: number): void

interface SpawnOptions {

Properties

command: string
argv: string[]
env: Record<string, string>
cwd?: string
defaultSignals?: number[]
createSession?: boolean
closeOnExecDefault?: boolean

Methods

configure(actions: SpawnActions): void

interface ChildExitStatus {

Properties

code: number | null
signal: number | null

Functions

function spawnPosix(options: SpawnOptions): number

Launch a child after applying caller-provided descriptor actions.

async function watchChildExit(pid: number): Promise<ChildExitStatus>

Wait asynchronously for a child and reap it exactly once.

function closeFd(fd: number): void

function setFdNonblocking(fd: number): void

function signalChild(pid: number, signal: number): void

function trySignalChild(pid: number, signal: number): boolean

Signal a child when teardown should tolerate an already-exited target.