process
Subprocess spawning. Cross-platform: fork + execvp on POSIX, CreateProcess on Windows, selected by target.
public module process::signal;
public module process::child;
public module process::command;
public module process::exec;
| File | What it holds | Import |
|---|---|---|
command | Command, Stdio, Output | import std::process::command; |
child | Child, ExitStatus, the piped ChildStdin / ChildStdout / ChildStderr | import std::process::child; |
signal | Signal, SigNo | import std::process::signal; |
exec | shell, one command line through the platform shell | import std::process::exec; |
The current process
function id() -> i32;
function id() -> i32;The current process's OS process id (pid). On POSIX this is getpid(); on Windows it is GetCurrentProcessId(), both surfaced through libc::getpid.
id() is the current process's pid — getpid() on POSIX, GetCurrentProcessId() on Windows. It lives at the root of the module: import std::process;.
public function name() { ... }
public:Visible to any module that imports this one - the default for top-level items and for struct fields, so it is mostly written to be explicit. public: opens a visibility block that groups the members after it.
public module collections::array;In a directory's _module.cryo aggregator, lists a submodule and whether it is public. Importing the directory's namespace sees only the modules declared public here.
type struct Command {
program: String;
args: Array<String>;
envs: Array<EnvEntry>;
clear_env_flag: boolean;
cwd: Option<String>;
stdin_cfg: Stdio;
stdout_cfg: Stdio;
stderr_cfg: Stdio;
}Command: builder for spawning a subprocess.
std::process::commandtype enum Stdio {
Inherit;
Null;
Piped;
Fd(i32);
}How a child's stdin / stdout / stderr is wired up.
std::process::commandtype struct Output {
status: ExitStatus;
stdout: Array<u8>;
stderr: Array<u8>;
}import a::b;
import a::b::{ X, Y };
import a::b as c;
import a::b::*;Brings a module, or selected items from it, into scope. One path per declaration: use the brace form for several items, as to alias, and * for everything public (prefer the brace form; wildcards invite name collisions).
type struct Child {
stdin: Option<ChildStdin>;
stdout: Option<ChildStdout>;
stderr: Option<ChildStderr>;
}Child: a running subprocess.
std::process::childtype struct ExitStatus {
code: i32;
signal: i32;
signaled: boolean;
}Result of a child's termination. Either it exited normally with a code, or it was killed by a signal. POSIX encodes both into a single wstatus word; ExitStatus is the decoded form.
type struct ChildStdin {
fd: i32;
}Write end of a pipe whose read end is the child's stdin.
std::process::childtype struct ChildStdout {
fd: i32;
}Read end of a pipe whose write end is the child's stdout.
std::process::childtype struct ChildStderr {
fd: i32;
}Read end of a pipe whose write end is the child's stderr.
std::process::childtype enum SigNo : i32 {
SIGHUP = 1;
SIGINT = 2;
SIGQUIT = 3;
SIGILL = 4;
SIGTRAP = 5;
SIGABRT = 6;
SIGBUS = 7;
SIGFPE = 8;
SIGKILL = 9;
SIGUSR1 = 10;
// … 9 more
}function name<T>(param: Type) -> Ret { ... }Declares a function. Parameters are written name: Type and are never inferred; the return type follows -> and defaults to void. Declaration order does not matter: every signature is collected before any body is checked, so functions may call each other freely and recurse.
function id() -> i32The current process's OS process id (pid). On POSIX this is getpid(); on Windows it is GetCurrentProcessId(), both surfaced through libc::getpid.
extern "C" function getpid() -> i32extern "C" function GetCurrentProcessId() -> u32function id() -> i32The current process's OS process id (pid). On POSIX this is getpid(); on Windows it is GetCurrentProcessId(), both surfaced through libc::getpid.