Reference

std/os/system

std/os/src/system.trb

System - which operating system this is and which version, the host name, how long it has been running, the size of a memory page and the architecture of the machine - and SystemVersion, the name and version it answers.

Every question is a match OperatingSystem.current whose arm hands it to the directory of that system; only the arm of the build's target is compiled.

type System

type System

Which system this is, which version, and how long it has been running.

Examples

const version = System.version()?
print "{version.name} on {System.hostName()?}"

Related

fn version

static fn version(): Result<SystemVersion, OsError>

The operating system's name and version, as its vendor writes them. Windows reads its registry and its kernel, Linux os-release and uname, macOS sysctl, FreeBSD uname.

Examples

const version = System.version()?
print "{version.name} {version.kernel}"

fn hostName

static fn hostName(): Result<String, OsError>

The machine's host name, without a domain: GetComputerNameExW(ComputerNameDnsHostname) on Windows, gethostname everywhere else. It never asks DNS.

fn uptime

static fn uptime(): Result<Duration, OsError>

How long since the system started, as each system counts it: GetTickCount64 on Windows, /proc/uptime on Linux, kern.boottime against the clock on macOS and FreeBSD. All four include the time the machine was asleep.

fn pageSize

static fn pageSize(): Int

The size of a memory page in bytes: 4096 on most machines, 16384 on Apple silicon. Every system knows it without failing, so the answer is not a Result.

fn machineArchitecture

static fn machineArchitecture(): Result<Architecture, OsError>

The architecture of the machine, which is not always Architecture.current: an x86-64 program emulated on an Arm64 Windows machine, or translated by Rosetta on a Mac, runs on .Arm64.

type SystemVersion

type SystemVersion with Show, Equals

The name and version of the running system.

Examples

const version = SystemVersion(
  name: "Ubuntu 24.04.1 LTS",
  identifier: "ubuntu",
  release: "24.04",
  build: None,
  kernel: "6.8.0-45-generic",
)
print version.kernelNumbers()

field name

name: String

For people: Windows 11 Pro, Ubuntu 24.04.1 LTS, macOS 15.1, FreeBSD 14.1-RELEASE.

field identifier

identifier: String

For programs, stable and lower case: windows, ubuntu, fedora, macos, freebsd (ID of os-release).

field release

release: String

The product's own version: 24H2, 24.04, 15.1, 14.1.

field build

build: String?

The build, where the product has one: 26100.2314, 24B83.

field kernel

kernel: String

The kernel's release: 10.0.26100, 6.8.0-45-generic, 24.1.0, 14.1-RELEASE.

fn kernelNumbers

fn kernelNumbers(): List<Int>

The leading numbers of SystemVersion.kernel, for comparing: [6, 8, 0] of 6.8.0-45-generic.