Skip to content
Jaskirat Rajasansir edited this page Apr 17, 2024 · 7 revisions

Operating System Abstraction Library

This library provides an abstraction layer to some commonly used Operating System functionality.

Currently supported:

  • Windows (w)
  • Linux (l)
  • Mac OS X (m)

.os.availableCommands

This function returns the available commands for the operating system that the kdb process is running on

.os.type

Set on library initialisation with the current OS type as a symbol (e.g. l = Linux)

.os.envPathSeparator

The separator character for PATH-type environment variables on the current OS:

  • Linux / Mac / Solaris: :
  • Windows: ;

.os.sharedObjectEnvVar

The PATH-type environment variable to use to search for shared libraries (see so.q.md for an implementation example):

  • Linux / Solaris: LD_LIBRARY_PATH
  • Mac: DYLD_LIBRARY_PATH
  • Windows: PATH

.os.run

Use this function to execute the OS functionality

Example

q) .os.run[`pwd;::]
Running system command: "echo %cd%"
"C:\\Users\\jasra_000\\git\\kdb-common "

/ Ensure the file library is loaded
q) newFolder:.convert.hsymToString ` sv .file.getCwd[],`mkdirTest
q) .os.run[`mkdir; newFolder]
Running system command: "mkdir C:\Users\jasra_000\git\kdb-common\mkdirTest"
q)

.os.isProcessAlive

This function returns a boolean if the specified PID is valid and exists on the current server (using the pidCheck OS command)

.os.getTerminalSize

This function returns the current terminal window size in 'system "c"' format - lines columns (using the terminalSize OS command)

Example

q).os.getTerminalSize[]
Running system command: "stty size"
"85 156"

.os.isInteractiveSession

This function returns true if the kdb process is running in an interactive session, false otherwise

Example

q).os.isInteractiveSession[]
Running system command: "tty --quiet; echo $?"
1b
> echo '.require.init[]; .require.lib`os; .os.isInteractiveSession[]' | $QHOME/l64/q src/require.q
...
Initialised library: os
Running system command: "tty --quiet; echo $?"
0b

.os.getProcessArchitecture

This function returns the process architecture as either x86 (32-bit) or x86_64 (64-bit)

Example

q).os.getProcessArchitecture[]
`x86_64

Available Commands

  • mkdir: Create a directory including any intermediate directories that do not exist
  • rmdir: Remove an empty directory
  • pwd: Print the current working directory
  • rm: Delete a non read-only file, logging what is being deleted
  • rmF: Delete any file, logging what is being deleted
  • rmFolder: Remove a folder and all its contents
  • safeRmFolder: Remove a folder only if it is empty
  • ln: Create a symbolic link
  • mv: Move a file or folder
  • cpFolder: Copy a folder and it's contents
  • pidCheck: If the specified PID is active on the current server
  • sigint: Send a SIGINT signal to the specified PID
  • sigterm: Send a SIGTERM signal to the specified PID
  • sigkill: Send a SIGKILL signal to the specified PID
  • sleep: Delay for a fixed amount of time (interval type is defined by the underlying OS command)
  • tail: Return the latest lines from a file
  • procCount: Query the number of CPU cores on the current server
  • which: Find the full path of a shell command
  • ver: Query the version string of the application
  • cpuAssign: Returns the CPU cores that the current process is assigned to
  • terminalSize: The size of the current terminal that process is running within
  • isInteractive: If the current process is running within an interactive terminal or not
Clone this wiki locally