Source Edit

A set of helpers for the POSIX module. Raw interfaces are in the other posix*.nim files.

Imports

posix, parsecfg, os, since

Types

  1. Uname = object
  2. sysname*, nodename*, release*, version*, machine*: string

Source Edit

Procs

  1. proc fsync(fd: int) {....raises: [OSError], tags: [], forbids: [].}

synchronize a file’s buffer cache to the storage device Source Edit

  1. proc memoryLock(a1: pointer; a2: int) {....raises: [OSError], tags: [], forbids: [].}

Locks pages starting from a1 for a1 bytes and prevent them from being swapped. Source Edit

  1. proc memoryLockAll(flags: int) {....raises: [OSError], tags: [], forbids: [].}

Locks all memory for the running process to prevent swapping.

example:

  1. memoryLockAll(MCL_CURRENT or MCL_FUTURE)

Source Edit

  1. proc memoryUnlock(a1: pointer; a2: int) {....raises: [OSError], tags: [],
  2. forbids: [].}

Unlock pages starting from a1 for a1 bytes and allow them to be swapped. Source Edit

  1. proc memoryUnlockAll() {....raises: [OSError], tags: [], forbids: [].}

Unlocks all memory for the running process to allow swapping. Source Edit

  1. proc mkdtemp(prefix: string): string {....raises: [OSError], tags: [], forbids: [].}

Creates a unique temporary directory from a prefix string. Adds a six chars suffix. The directory is created with permissions 0700. Returns the directory name. Source Edit

  1. proc mkstemp(prefix: string; suffix = ""): (string, File) {....raises: [OSError],
  2. tags: [], forbids: [].}

Creates a unique temporary file from a prefix string. A six-character string will be added. If suffix is provided it will be added to the string The file is created with perms 0600. Returns the filename and a file opened in r/w mode. Source Edit

  1. proc osReleaseFile(): Config {....raises: [IOError, OSError, Exception, ValueError,
  2. KeyError], tags: [ReadDirEffect,
  3. WriteIOEffect, ReadIOEffect, RootEffect], forbids: [].}

Gets system identification from os-release file and returns it as a parsecfg.Config. You also need to import the parsecfg module to gain access to this object. The os-release file is an official Freedesktop.org open standard. Available in Linux and BSD distributions, except Android and Android-based Linux. os-release file is not available on Windows and OS X by design.

Example:

  1. import std/parsecfg
  2. when defined(linux):
  3. let data = osReleaseFile()
  4. echo "OS name: ", data.getSectionValue("", "NAME") ## the data is up to each distro.

Source Edit

  1. proc sendSignal(pid: Pid; signal: int) {....raises: [OSError], tags: [],
  2. forbids: [].}

Sends a signal to a running process by calling kill. Raise exception in case of failure e.g. process not running. Source Edit

  1. proc stat(path: string): Stat {....raises: [OSError], tags: [], forbids: [].}

Returns file status in a Stat structure Source Edit

  1. proc uname(): Uname {....raises: [OSError], tags: [], forbids: [].}

Provides system information in a Uname struct with sysname, nodename, release, version and machine attributes. Source Edit