docs

Faux OS API documentation

View on GitHub

Table of Contents

spawn

Spawn a new process from an executable image

Parameters

  • image string The executable code to run (optional, default "")
  • argv array Argument vector for the new process (optional, default [])

Examples

sys.spawn("console.log(argv)", ["hello", "world"])

Returns Promise<number> pid - The ID of the new process

exec

Spawn a new process from a path

Parameters

  • path string The executable code file’s path
  • argv array (optional, default [])

Examples

sys.exec("/bin/ls", ["ls", "-a"])

Returns Promise<number> pid

exists

Check if a file exists

Parameters

Examples

const exists = await sys.exists("/file")

Returns Promise<boolean>

stat

Get file/directory info

Parameters

Examples

const info = await sys.stat("/file")

Returns Promise<object>

open

Open a file/directory to get its file descriptor

Parameters

  • path string
  • mode (optional, default "r")

Examples

const fd = await sys.open("/file")

Returns Promise<number> fd - new file descriptor

close

Close a file descriptor from use

Parameters

Examples

sys.close(3)

dup

Duplicate a file descriptor

Parameters

  • fd number File descriptor to copy

Examples

const copied = await sys.dup(0)

Returns Promise<number> duplicated file descriptor

dup2

Duplicate a file descriptor to a new location, possibly overwriting one

Parameters

  • fd1 number File descriptor to copy
  • fd2 number Target to copy to

Examples

sys.dup2(1, 2)

Returns Promise<number> Second file descriptor

read

Read file contents from a file descriptor

Parameters

Examples

const contents = await sys.read(fd)

Returns Promise<string> data - file contents

write

Write data to a file descriptor

Parameters

  • fd number
  • data string new file contents (optional, default "")

Examples

sys.write(1, "hello world")

pwd

Get the currect working directory

Examples

const cwd = await sys.pwd()

Returns Promise<string> current working directory

chdir

Change the working directory

Parameters

  • path string new working directory (optional, default "/home")

Examples

sys.chdir("/home")

getenv

Get an environment variable value by key, invoke with no arguments to return the whole environment variable object

Parameters

Examples

const usingAwait = (await sys.getenv("PATH")).split(":")
const usingPromise = sys.getenv("PATH").then(path => path.split(":"))

Returns Promise<string> value

setenv

Set an environment variable to a new value

Parameters

Examples

sys.setenv("varName", "It doesn't have to be all caps")