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

NextPrevUpTopContentsIndex

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 UNIX 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 environment is already running. Note that, on Windows, Mac OS X, Linux, x86/x64 Solaris and FreeBSD, the LispWorks images shipped do start the programming environment. If you create an image which does not start the programming environment, by using the :environment nil argument to save-image, then multiprocessing can be started in this new image as described below.

19.2.3.1 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*.

19.2.3.2 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"
:restart-function 'mp:initialize-multiprocessing)

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 LispWorks Delivery User Guide for more details.

LispWorks dynamic libraries always start multiprocessing on startup. See 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: On Windows, Linux, x86/x64 Solaris, FreeBSD and Mac OS X you cannot save a LispWorks image with multiprocessing running.

19.2.3.3 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.

(load-all-patches)
(load "my-server-code")
(push '("Start Server" () start-my-server)
      mp:*initial-processes*)
(save-image "my-server"
            :remarks "My Server"
            :restart-function 'mp:initialize-multiprocessing
            :environment nil)

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


LispWorks User Guide and Reference Manual - 13 Feb 2015

NextPrevUpTopContentsIndex