Standard library · System and tools

os/platform

Identifying the system the program is running on: the operating system, the processor, the core count and the memory.

import os.platform
On this page
  1. Functions

The os.platform package says at run time what system the program is on. For decisions that belong at compile time, constants such as SALAM_OS_WINDOWS and conditional compilation are the better fit; this package is for reports, automatic settings and messages.

The example below prints whether the properties hold rather than the system's name, so that its output is the same everywhere.

Functions

IsLinux

func IsLinux(): bool
True on Linux.
os-platform-OS.salam
import os.platform

func main:
    known := platform.IsLinux() or platform.IsWindows() or platform.IsMac() or platform.IsFreeBSD() or platform.IsBSD() or platform.IsAndroid() or platform.IsWasm()
    println known, platform.OS().len() > 0
    arch := platform.IsX64() or platform.IsArm64() or platform.IsX86() or platform.IsArm()
    println arch, platform.Arch().len() > 0
    println platform.CpuCount() >= 1
    println platform.TotalMemory() > 0, platform.AvailableMemory() <= platform.TotalMemory()
end
Outputtrue true true true true true true

IsWindows

func IsWindows(): bool
True on Windows.

The example for this item is shown with the ones above: os-platform-OS.salam

IsMac

func IsMac(): bool
True on macOS.

The example for this item is shown with the ones above: os-platform-OS.salam

IsBSD

func IsBSD(): bool
True on the BSD family.

The example for this item is shown with the ones above: os-platform-OS.salam

IsFreeBSD

func IsFreeBSD(): bool
True on FreeBSD.

The example for this item is shown with the ones above: os-platform-OS.salam

IsAndroid

func IsAndroid(): bool
True on Android.

The example for this item is shown with the ones above: os-platform-OS.salam

IsWasm

func IsWasm(): bool
True when the program was compiled to WebAssembly.

The example for this item is shown with the ones above: os-platform-OS.salam

OS

func OS(): str
The name of the operating system: linux, mac, windows, freebsd, android or wasm.

The example for this item is shown with the ones above: os-platform-OS.salam

IsX64

func IsX64(): bool
True on a 64-bit Intel or AMD processor.

The example for this item is shown with the ones above: os-platform-OS.salam

IsArm64

func IsArm64(): bool
True on a 64-bit ARM processor, such as Apple silicon.

The example for this item is shown with the ones above: os-platform-OS.salam

IsX86

func IsX86(): bool
True on a 32-bit Intel processor.

The example for this item is shown with the ones above: os-platform-OS.salam

IsArm

func IsArm(): bool
True on a 32-bit ARM processor.

The example for this item is shown with the ones above: os-platform-OS.salam

Arch

func Arch(): str
The name of the processor architecture, such as x64 or arm64.

The example for this item is shown with the ones above: os-platform-OS.salam

CpuCount

func CpuCount(): int
The number of processor cores, for deciding how many things to do at once.

The example for this item is shown with the ones above: os-platform-OS.salam

TotalMemory

func TotalMemory(): i64
The system's total memory in bytes.

The example for this item is shown with the ones above: os-platform-OS.salam

AvailableMemory

func AvailableMemory(): i64
The free memory in bytes. Supported on Linux and Windows only; elsewhere it returns minus one.

The example for this item is shown with the ones above: os-platform-OS.salam