The os module provides simple, cross-platform access to operating system information and utilities.
It is designed to be:
- simple
- predictable
- cross-platform
- dependency-free (except core Vix modules)
- consistent with the Vix API design
The os module follows strict principles:
- no hidden behavior
- explicit error handling (
Result<T>) - minimal abstractions
- platform differences handled internally
- stable and portable API
The goal is to give modern OS capabilities in C++ without friction.
Using Vix:
vix add @vix/os#include <vix/os/Os.hpp>
#include <iostream>
int main()
{
auto platform = vix::os::platform();
auto arch = vix::os::arch();
if (platform && arch)
{
std::cout << platform.value() << " / " << arch.value() << "\n";
}
}vix::os::platform(); // linux, windows, macos
vix::os::arch(); // x86_64, arm64, ...
vix::os::kernel_version(); // kernel version
vix::os::hostname(); // machine hostnamevix::os::current_user(); // username, home, shell
vix::os::current_pid(); // process id
vix::os::is_admin(); // admin / root checkvix::os::home_dir(); // user home directory
vix::os::temp_dir(); // temp directoryvix::os::cpu_count(); // number of logical CPUs
vix::os::page_size(); // memory page size
vix::os::uptime(); // system uptime (seconds)vix::os::sleep_for_ms(500);
vix::os::sleep_for_seconds(1);All functions returning data use:
vix::error::Result<T>Example:
auto result = vix::os::hostname();
if (!result)
{
std::cerr << result.error().message() << "\n";
}
else
{
std::cout << result.value() << "\n";
}struct UserInfo
{
std::string username;
std::string home_dir;
std::string shell;
};struct OsInfo
{
std::string platform;
std::string architecture;
std::string kernel_version;
std::string hostname;
};struct CpuInfo
{
std::string model;
std::uint32_t cores;
std::uint32_t threads;
};struct MemoryInfo
{
std::uint64_t total_bytes;
std::uint64_t available_bytes;
};#include <vix/os/Os.hpp>
#include <iostream>
int main()
{
auto host = vix::os::hostname();
if (host)
{
std::cout << host.value() << "\n";
}
}auto cpu = vix::os::cpu_count();
auto uptime = vix::os::uptime();- Uses native system APIs internally
- Avoids heavy dependencies
- Designed for CLI tools, servers, and system-level applications
- Compatible with Linux, macOS, and Windows
- detailed CPU information
- memory statistics per process
- environment introspection integration
- advanced process and system metrics
The os module gives you:
- system identity
- user and process info
- directories
- hardware basics
- simple OS utilities
All in a clean, modern C++ API.
A modern runtime for real-world C++ systems.