Unicorn-inspired PicoLisp daemon to spawn and manage worker processes

You can get it on GitHub.

This program mimics functionality of Unicorn, without being limited to HTTP applications.

The included supervisor.l can be used to spawn multiple worker processes which perform tasks in an infinite loop.

Supervisor

  1. Requirements
  2. Getting Started
  3. Usage
  4. Note and Limitations

Requirements

Getting Started

This library is written in pure PicoLisp and contains no external dependencies.

To ensure everything works on your system, run the tests first: make check

Try the test app

Launch the Supervisor with: ./supervisor.l --app testapp.l

You’ll see output showing 1 worker “Performing a task” in a loop. Wait until it completes a task or two, then press Ctrl+C or send an INT signal to tell the parent process to exit, along with its worker.

# example output
./supervisor.l --app testapp.l --workers 2
parent process ready pid=814
spawning 2 missing workers:
worker[0] spawning..
worker[1] spawning..
worker[0] spawned pid=815
worker[0] pid=815 do this after forking
worker[0] ready
worker[0] pid=815 Performing a task: sleeping for 12 seconds
worker[1] spawned pid=816
worker[1] pid=816 do this after forking
worker[1] ready
worker[1] pid=816 Performing a task: sleeping for 9 seconds
worker[1] pid=816 Performing a task: sleeping for 16 seconds
^Cworker[1] exited
worker[0] exited
parent exited

Feel free to observe the example code in testapp.l.

Usage

The supervisor runs in the foreground and simply manages the worker processes. If a worker (child process) exits, it will be re-spawned automatically by the supervisor. The supervisor periodically checks for missing workers, depending on the *SV_POLL_TIMEOUT variable.

# supervisor.l
Usage:                    ./supervisor.l --app <yourapp> [option] [arguments]

Example:                  ./supervisor.l --app app.l --workers 4 --poll 1

Options:
--help                    show this help message and exit

--app <yourapp>           Filename of the app which contains (worker-start)
--poll <seconds>          Number of seconds to poll for missing workers (default: 30)
--preload                 Load the app in the parent before forking the worker process (default: No)
--workers <number>        Number of workers to spawn (default: 1)

Options

Notes and limitations

This section will explain some important technical details about the code, and limitations on what this app can and can’t do.

Technical notes

Limitations