Module: sys.process
Source: ./sys/process.reef
Overview
sys/process - Process spawning and management
Provides functions for spawning child processes, executing shell commands, and managing process lifecycle.
Example - Run a command and wait: let pid = process_spawn_shell("ls -la") if pid > 0 let exit_code = process_wait(pid) println("Command exited with code: ${exit_code}") end if
Example - Non-blocking wait: let pid = process_spawn_shell("sleep 5") while not process_try_wait(pid) println("Still running...") sleep(1000) end while println("Done! Exit code: ${process_exit_code()}")
Example - Kill a process: import sys.signal let pid = process_spawn_shell("sleep 100") process_kill(pid, SIGTERM())
Functions
fn process_spawn_shell(command: string): int
Spawn a shell command Returns PID on success, -1 on error
fn process_wait(pid: int): int
Wait for a process to exit (blocking) Returns exit code, or -1 on error
fn process_try_wait(pid: int): bool
Non-blocking wait - check if process has exited Returns true if process has exited, false if still running
fn process_kill(pid: int, signum: int): bool
Send a signal to a process Returns true on success
fn process_exit_code(): int
Get exit code from last wait operation
fn process_exited_normally(): bool
Check if last waited process exited normally (vs signaled)
fn process_was_signaled(): bool
Check if last waited process was killed by a signal
fn process_term_signal(): int
Get the signal that terminated the process (if signaled)
fn getpid(): int
Get current process ID
fn getppid(): int
Get parent process ID
fn process_fork(): int
Fork the current process Returns child PID in parent, 0 in child, -1 on error
fn process_spawn(program: string, argv: [string]): int
Spawn a program with the given argv vector (POSIX execve semantics).
argv[0] is conventionally the program name; the runtime does NOT
prepend program for you. If you want Python/Go-style auto-prepend,
use process_run instead.
Returns child PID on success, -1 on error.
fn process_exec(program: string, argv: [string]): int
Replace current process with program (POSIX execve semantics; does not
return on success). argv[0] is conventionally the program name; the
runtime does NOT prepend program for you. For the higher-level
wrapper, use process_run_exec.
fn process_run(program: string, arg_list: [string]): int
high-level wrapper matching Python subprocess.run / Go exec.Command convention. Builds argv as [program, ...arg_list] so callers pass only the trailing arguments and don't have to think about argv[0]. Returns child PID on success, -1 on error.
Parameter is named arg_list (not args) because consumers
commonly alias import sys.optparse as args, which collides with a
parameter named args. The compiler rejects that collision, but the
rename keeps the stdlib defensive.
fn process_run_exec(program: string, arg_list: [string]): int
Exec variant of process_run — replace current process, auto-prepending program as argv[0]. Does not return on success.
fn process_setsid(): int
Create a new session (setsid) Returns new session ID on success, -1 on error
fn process_getpgid(pid: int): int
Get process group ID
fn process_setpgid(pid: int, pgid: int): int
Set process group ID
fn process_wait_any(): int
Wait for any child process (blocking) Returns PID of exited child, -1 on error
fn process_wait_any_nohang(): int
Non-blocking wait for any child Returns PID of exited child, 0 if none ready, -1 on error
fn killpg(pgrp: int, sig: int): int
Send signal to a process group
fn umask(mask: int): int
Set file creation mask Returns previous mask value
Procedures
proc exit_now(code: int)
Immediately exit process without cleanup Use this in forked child processes to avoid running GC/AO cleanup
Generated by reefc doc