All Manuals > LispWorks® User Guide and Reference Manual > 19 Multiprocessing

19.2 Processes basics

19.2.1 Creating a process

To create a new process, use process-run-function.

A process can exit either by returning from the process function or by calling current-process-kill.

19.2.2 Finding out about processes

The system initializes a number of processes on startup. These processes are specified by *initial-processes*.

The current process is obtained by get-current-process. A list of all the current processes is returned by list-all-processes and the number of them is returned by processes-count. The function ps is analogous to the POSIX command ps, and returns a list of the processes in the system, ordered by priority.

To find a process when you know its name, use get-process. To find the name, when you have the process, use process-name. The variable *process-initial-bindings* specifies the variables that are initially bound in a process.

19.2.3 Multiprocessing

To start multiprocessing, use initialize-multiprocessing. This function does not return until multiprocessing has terminated.

It is not necessary to use initialize-multiprocessing when the LispWorks IDE is already running. Note that, on Windows, macOS, Linux, x86/x64 Solaris and FreeBSD, the LispWorks images shipped do start the IDE. If you create an image which does not start the IDE, by using the :environment nil argument to save-image, then multiprocessing can be started in this new image as described below. Starting multiprocessing interactively

You can call initialize-multiprocessing from the REPL interface, which generates a default Listener process if no other processes are specified by *initial-processes*. Multiprocessing on startup

There are three ways to make a LispWorks executable start multiprocessing on startup.

1. Use the -multiprocessing command line argument.

2. Save an image which starts multiprocessing by doing:

(save-image "mp-lispworks" :multiprocessing t)

3. Use delivery to create the executable and pass the argument :multiprocessing t to deliver. The delivery function will be called automatically in a new process. See the Delivery User Guide for more details.

LispWorks dynamic libraries always start multiprocessing on startup. See 14.5 Multiprocessing in a dynamic library for more information.

In all cases, *initial-processes* can be used to control which processes are created on startup, as described in Running your own processes on startup.

Note: You cannot save a LispWorks image with multiprocessing running. Running your own processes on startup

*initial-processes* is a list of lists. Each list is used by the system as a set of arguments to process-run-function. During initializing multiprocessing, the system does this:

(dolist (x mp:*initial-processes*)
  (apply 'mp:process-run-function x))

This script saves a LispWorks image which starts multiprocessing on restart and runs a user-defined process.

(in-package "CL-USER")
(load "my-server-code")
(push '("Start Server" () start-my-server)
(save-image "my-server"
            :remarks "My Server"
            :multiprocessing t
            :environment nil)

See save-image for a description of how to save an image.

LispWorks® User Guide and Reference Manual - 01 Dec 2021 19:30:21