Skip to content

System

The @std/system module provides process control, system information, file descriptors, and filesystem helpers.

import system from "@std/system"
println(system.osName())
println(system.arch())
println(system.cwd())
NameTypeDescription
stdinintStandard input file descriptor.
stdoutintStandard output file descriptor.
stderrintStandard error file descriptor.
import system from "@std/system"
println(system.stdin)
println(system.stdout)
println(system.stderr)
NameDescription
argsReturns the process arguments as []string.
exitExits the process with a code.
abortPrints a fatal error and kills the current process.
pidReturns the current process ID.
killKills a process by PID.
import system from "@std/system"
println(system.args())
println(system.pid())

Exit with a status code:

import system from "@std/system"
system.exit(0)

Abort the current process:

import system from "@std/system"
system.abort("Fatal error")

Kill a process by ID:

import system from "@std/system"
let current = system.pid()
system.kill(current)
NameReturnsDescription
osNamestringOperating system name.
archstringCPU architecture.
hostnamestringHostname.
userstringCurrent user name.
cpuintNumber of CPUs.
memoryTotalintTotal system memory in bytes.
memoryFreeintFree or available system memory in bytes.
uptimeintSystem uptime in seconds.
isTTYboolWhether a file descriptor is a TTY.
import system from "@std/system"
println("OS:", system.osName())
println("Arch:", system.arch())
println("Host:", system.hostname())
println("User:", system.user())
println("CPUs:", system.cpu())
println("Total memory:", system.memoryTotal())
println("Free memory:", system.memoryFree())
println("Uptime:", system.uptime())
println("stdout is TTY:", system.isTTY(system.stdout))
NameReturnsDescription
cwdstringCurrent working directory.
chdirvoidChanges the current working directory.
tempDirstringSystem temporary directory.
import system from "@std/system"
let before = system.cwd()
println("Before:", before)
println("Temp:", system.tempDir())
system.chdir(system.tempDir())
println("After:", system.cwd())

Function implementations use the return type after the parameter list.

fn printSystemInfo() void {
println(system.osName())
println(system.arch())
}