Process (std::process)
std::process exposes the running Zolo process: command-line arguments, PID,
working directory, subprocess execution, and memory-usage telemetry. All
functions interact with the host and cannot be run in the WASM sandbox; use
the Zolo CLI.
Arguments, working directory, and PID
process.argv() returns an array of arguments (index 0 is the executable
or "zolo"). process.cwd() returns the current directory. process.pid()
and process.ppid() return the process ID and parent process ID:
Prints argv, cwd, pid, and ppid of the current process.
// Feature: process.argv / process.cwd / process.pid — process info
// When to use: read command-line arguments, debugging, relative paths.
use std::process
// argv() -> array of arguments (includes the executable name at [0]).
let args = process.argv()
print(args.len() >= 1) // expected: true
print(args[0]) // expected: path of the binary (or "zolo")
// cwd() -> current directory (absolute string).
let dir = process.cwd()
print(dir.len() > 0) // expected: true
// pid() -> ID of the current process.
let pid = process.pid()
print(pid > 0) // expected: true
// ppid() -> ID of the parent process.
let ppid = process.ppid()
print(ppid > 0) // expected: true
Requires the Zolo CLI/host — open in the playground or run locally.
Run and wait for subprocesses
process.exec(cmd, args?) blocks until the command finishes and returns
{ stdout, stderr, status }. process.spawn(cmd, args?) starts in the
background and returns { pid }; use process.wait(pid) to collect the result
or process.kill(pid) to terminate it:
Runs git --version in blocking mode and launches git status in the background.
// Feature: process.exec / process.spawn — run external commands
// When to use: scripts that orchestrate git, ffmpeg, external builders.
use std::process
// exec(cmd, args?) blocks and returns { stdout, stderr, status }.
let result, err = process.exec("git", ["--version"])
if err == nil {
print(result.status) // expected: 0
print(result.stdout.len() > 0) // expected: true
}
// spawn(cmd, args?) starts in the background and returns { pid }.
// Use process.wait(pid) to collect the result, process.kill(pid) to kill.
let proc, e2 = process.spawn("git", ["status"])
if e2 == nil {
print(proc.pid > 0) // expected: true
let out = process.wait(proc.pid)
print(out.status >= 0) // expected: true
}
Requires the Zolo CLI/host — open in the playground or run locally.
Uptime, memory, and exit
process.uptime() returns the seconds since the process started.
process.memory_usage() provides { rss, vsize } in bytes. process.sleep(ms)
pauses the process (prefer io_runtime.sleep_ms when other I/O is in flight).
process.exit(code) exits immediately, running any on shutdown hooks:
Demonstrates uptime, memory_usage, and sleep; exit is commented out to avoid interruption.
// Feature: process.exit / process.sleep / process.uptime / process.memory_usage
// When to use: scheduled shutdowns, daemons, telemetry.
use std::process
// uptime() -> seconds (float) since the process started.
let up = process.uptime()
print(up >= 0.0) // expected: true
// memory_usage() -> { rss, vsize } in bytes.
let mem = process.memory_usage()
print(mem.rss > 0) // expected: true
// sleep(ms) blocks the process for N ms (see also the `sleep <duration>` keyword).
process.sleep(10)
print("woke up") // expected: woke up
// exit(code) terminates immediately, running `on shutdown` first.
// process.exit(0) — success
// process.exit(1) — error
// (we don't call it here so the example keeps running.)
print("alive until the end") // expected: alive until the end
Requires the Zolo CLI/host — open in the playground or run locally.
Summary introspection
A compact dashboard with PID, PPID, uptime, and memory usage in a single block — useful for startup logs and health reports:
Prints PID, PPID, uptime, and memory usage with f-strings.
// Process introspection extras (Slice 1 of lifecycle hooks).
// Companion: specs/lifecycle-hooks.md
use std::process
print("pid: {process.pid()}")
print("ppid: {process.ppid()}")
print("uptime: {process.uptime()}s")
let mem = process.memory_usage()
print("memory: rss={mem.rss} bytes, vsize={mem.vsize} bytes")
Requires the Zolo CLI/host — open in the playground or run locally.
See also