Skip to content

Process (std::process)

On this page

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.

01-args-cwd.zolo
// Feature: process.argv / process.cwd / process.pid — process info

// When to use: read command-line arguments, debugging, relative paths.

// parity-normalize: path

//   argv[0] is the absolute path of the running binary (differs VM vs compiled

//   exe) — collapsed to <PATH>. The remaining lines are booleans and stay

//   exact, so a wrong boolean would still diverge.


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.

02-exec-spawn.zolo
// 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.

03-exit-uptime.zolo
// 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.

04-introspection.zolo
// Process introspection extras (Slice 1 of lifecycle hooks).

// Companion: specs/lifecycle-hooks.md

// Every value here is inherently per-run: pid/ppid vary, memory is live, and

// uptime is wall-clock (already collapsed by the harness's timing rule). The

// subs below neutralize ONLY the numeric operands, keeping the labels/units

// exact — a missing field or a `nil` still diverges.

// parity-sub: pid:\s+\d+ => pid: <N>

// parity-sub: ppid:\s+\d+ => ppid: <N>

// parity-sub: rss=\d+ => rss=<N>

// parity-sub: vsize=\d+ => vsize=<N>


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.

Search Zolo

9 results

enespt-br