Skip to content
Jaskirat Rajasansir edited this page Apr 16, 2024 · 2 revisions

Process Initialisation

The supplied boot.q script in the root of the repository provides a simple way to start a kdb+ process and initialise the kdb-common framework. It is optional, and require.q can still be loaded and initialised manually.

NOTE: boot.q should be referenced with an absolute path so require.q continues to work even if the process working directory is changed at a later point (e.g. with system "l").

Running q $(pwd)/boot.q will perform the following:

  1. Loads require.q
  2. Loads the following libraries
    • log
    • cargs
  3. Parses all command line arguments into .boot.args

Environment Variables

$KDB_APPLICATION_ROOT

This environment variable can be set to customise the root folder that require.q will be initialised from for library search for an application built with kdb-common.

NOTE: It is assumed that kdb-common exists as a folder at the top level of this folder.

Example:

> tree /tmp/my-application/
/tmp/my-application/
├── kdb-common -> /home/jas/git/kdb-common
└── src
    └── myLib.q
> export KDB_APPLICATION_ROOT=/tmp/my-application
> rlwrap $QHOME/l64/q /tmp/my-application/kdb-common/boot.q
...
Application root: /tmp/my-application | kdb-common root: /tmp/my-application/kdb-common
...
q) .require.lib`myLib
2021.11.05 15:26:32.723 INFO  pid-3264 jas 0 Loading library: myLib
2021.11.05 15:26:32.723 INFO  pid-3264 jas 0 Loading /tmp/my-application/src/myLib.q

Command Line Arguments

Boot Modes

--load-libs

This command line argument can be specified to load additional libraries during initialisation. Multiple libraries can be specified by comma-separating them.

Example:

> cd ~/git/kdb-common
> rlrwap $QHOME/l64/q $(pwd)/boot.q --load-libs compress,rand
...
Application root: /home/jas/git/kdb-common | kdb-common root: /home/jas/git/kdb-common
...
q) select from .require.loadedLibs where lib in `compress`rand
lib     | loaded loadedTime                    inited initedTime                    files
--------| ------------------------------------------------------------------------------------------------------------------
compress| 1      2021.11.05D15:28:55.892364000 1      2021.11.05D15:28:55.892389000 :/home/jas/git/kdb-common/src/compress.q
rand    | 1      2021.11.05D15:28:55.892665000 0                                    :/home/jas/git/kdb-common/src/rand.q

--script

This command line argument can be specified to load a specific q file (not via 'require'), optionally execute a function specified with --script-func and then automatically exit the process.

--debug

Enables the following features:

  • Error trap mode 1 (\e 1)
  • Stops the process exiting when running with --script

Useful Objects

A process started with boot.q will have the following objects available for use:

  • .boot.args: A dictionary of command line arguments, including kdb+ arguments
    • See .cargs.getWithInternal
  • .boot.root.kdbCommon: The root path where the kdb-common files reside
    • Based on the path of boot.q via .z.f
  • .boot.root.app: The root path where require.q has been initialised from for library search
    • This will only be different from .boot.root.kdbCommon if $KDB_APPLICATION_ROOT has been set
Clone this wiki locally