process.bend relies on unsafe/foreign
raw source on the hub · import bend-kit-process@0.5.2.3/process.bend as MProcess
Subprocesses and process-level OS access, with byte-exact input and output.
2 imports
import Base import bend-kit-bytes@0.3.3.3/bytes.bend as Bytes
Definitions
def stdin.read source · line 64 · raw
@max:U32 -> IO(Result<&1, &1, Pair(U32, String), String>)
def exit source · line 72 · raw
@code:U32 -> IO(Unit)
def run.result source · line 96 · raw
@r:Result<&1, &1, Pair(U32, String), Pair(U32, Pair(String, String))> -> Result<&1, &1, Pair(U32, String), Pair(U32, Pair(0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes, 0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes))>
def run source · line 104 · raw
@cmd:String -> @args:List<&2, String> -> @env:List<&2, String> -> @cwd:String -> @stdin:0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes -> IO(Result<&1, &1, Pair(U32, String), Pair(U32, Pair(0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes, 0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes))>)
def run.bounded source · line 113 · raw
@cmd:String -> @args:List<&2, String> -> @env:List<&2, String> -> @cwd:String -> @stdin:0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes -> @ms:U32 -> @max_out:U32 -> IO(Result<&1, &1, Pair(U32, String), Pair(U32, Pair(0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes, 0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes))>)
run with run.bounded.raw's deadline, output cap, and group kill.
def timed_out source · line 123 · raw
@timeout:U32 -> @code:U32 -> Bool
A deadline miss: code is the host's ETIMEDOUT, passed as timeout (from etimedout()), since ETIMEDOUT differs between systems.
def too_big source · line 127 · raw
@code:U32 -> Bool
Output past max_out: EFBIG is 27 on Linux and macOS.
Effects (foreign code)
effect run.raw source · line 9 · raw
@cmd:String -> @args:List<&2, String> -> @env:List<&2, String> -> @cwd:String -> @stdin:String -> IO(Result<&1, &1, Pair(U32, String), Pair(U32, Pair(String, String))>)
Environment entries are KEY=VALUE; they override inherited variables. The command is an executable name or path, never a shell expression. Exit status is 0..255, or 128 + the terminating signal number. cwd is the child's directory; relative paths start at the parent's directory.
foreign: effs/process.c, effs/process.js
effect spawn source · line 17 · raw
@cmd:String -> @args:List<&2, String> -> @env:List<&2, String> -> @cwd:String -> IO(Result<&1, &1, Pair(U32, String), Pair(U32, Pair(File, Pair(File, File)))>)
A streaming child: pid, writable stdin, readable stdout and stderr. Close stdin to send EOF; drain both outputs before wait to avoid pipe deadlock.
foreign: effs/process.c, effs/process.js
effect run.bounded.raw source · line 30 · raw
@cmd:String -> @args:List<&2, String> -> @env:List<&2, String> -> @cwd:String -> @stdin:String -> @ms:U32 -> @max_out:U32 -> IO(Result<&1, &1, Pair(U32, String), Pair(U32, Pair(String, String))>)
Like run.raw, bounded. The child leads its own process group. The call ends with SIGKILL to that group while it still holds the unreaped child, then reaps the child. ms is a deadline for the whole call (0: none); a miss is ETIMEDOUT. max_out caps stdout and stderr, each, in bytes (0: none); more is EFBIG. A descendant that keeps an output open holds the call until the deadline. A descendant that leaves the group (setsid, setpgid) escapes the kill. If anything else reaps the child first, nothing is signaled and the call fails with ECHILD; it also refuses (ECHILD) while SIGCHLD is ignored.
foreign: effs/process.c, effs/process.js
effect wait source · line 38 · raw
@pid:U32 -> IO(Result<&1, &1, Pair(U32, String), U32>)
Reaps a spawned child. A signaled child has status 128 + signal number. pid is 1..2147483647; 0 and larger are EINVAL, never group/any-child selectors.
foreign: effs/process.c, effs/process.js
effect wait.deadline source · line 44 · raw
@pid:U32 -> @ms:U32 -> IO(Result<&1, &1, Pair(U32, String), U32>)
Wait up to ms milliseconds; 0 means no deadline. ETIMEDOUT keeps the logical wait result available, not necessarily an unreaped OS child.
foreign: effs/process.c, effs/process.js
effect kill source · line 50 · raw
@pid:U32 -> @signal:U32 -> IO(Result<&1, &1, Pair(U32, String), Unit>)
Signal one positive pid, not necessarily a spawned child; 0 probes access. The caller must account for PID reuse. This never selects a process group.
foreign: effs/process.c, effs/process.js
effect etimedout source · line 55 · raw
IO(U32)
The host's ETIMEDOUT error code: 110 on Linux, 60 on macOS.
foreign: effs/process.c, effs/process.js
effect read_stdin source · line 60 · raw
@max:U32 -> IO(Result<&1, &1, Pair(U32, String), String>)
Read up to max bytes from this program's standard input; empty at EOF.
foreign: effs/process.c, effs/process.js
effect exit.raw source · line 68 · raw
@code:U32 -> IO(Unit)
Terminates this program with the supplied status.
foreign: effs/process.c, effs/process.js
effect cwd source · line 75 · raw
IO(Result<&1, &1, Pair(U32, String), String>)
foreign: effs/process.c, effs/process.js
effect chdir source · line 79 · raw
@path:String -> IO(Result<&1, &1, Pair(U32, String), Unit>)
foreign: effs/process.c, effs/process.js
effect hostname source · line 83 · raw
IO(Result<&1, &1, Pair(U32, String), String>)
foreign: effs/process.c, effs/process.js
effect pid source · line 87 · raw
IO(U32)
foreign: effs/process.c, effs/process.js
effect signal.poll source · line 92 · raw
IO(U32)
Install SIGINT/SIGTERM handlers and take one pending event; 0 means none.
foreign: effs/process.c, effs/process.js