Next: , Previous: , Up: Processes   [Contents][Index]


5.27.2 Asynchronous Processes

An asynchronous process is one that runs in parallel with Lisp evaluation, basically this means that once the subprocess has been started (by the start-process function) Librep will carry on as normal.

The event loop checks for output from asynchronous processes, any found is copied to the process’ output stream, and calls the the process’ state change function when necessary (see Process States). Alternatively the accept-process-output function can be called to explicitly allow output to be processed.

When using asynchronous processes you have a choice as to the Unix mechanism used to connect the stdin, stdout and stderr streams of the subprocess to Librep’s process.

The two options currently available are pipes or pseudo-terminals; in general pseudo-terminals should only be used to provide a direct interface between the user and a process (i.e. the ‘*shell*’ buffer) since they allow job control to work properly. At other times pipes will be more efficient and are used by default. However, there are cases where the buffering characteristics of pipes mean that ptys must be used.

Function: start-process #!optional process program #!rest args

This function starts an asynchronous subprocess running on the process object process. If process is undefined a new process object is created (by calling the function make-process with all arguments undefined).

The function always returns the process object which the subprocess has been started on. If for some reason the subprocess can’t be created an error of type process-error is signalled.

The optional argument program is a string defining the name of the program to execute, it will be searched for in all the directories in the PATH environment variable. The args are strings to pass to the subprocess as its arguments.

When defined, the optional arguments overrule the values of the related components of the process object.

The following example runs the ls program asynchronously, its output is sent to the standard-output stream.

(let
    ((process (make-process standard-output)))
  (start-process process "ls" "-s"))

Note that when Librep exits it kills all of its asynchronous subprocesses which are still running without warning.

Function: process-connection-type process

Returns the value of the connection type component of the process object process. See the documentation of the set-process-connection-type function for the values this may take.

Function: set-process-connection-type process symbol

Sets the value of the connection type component of the process object process to symbol, then returns symbol.

symbol should be one of the following symbols,

pty

Use pseudo-terminals to connect to subprocesses running asynchronously on this process object.

pipe

Use standard Unix pipes to connect, this is the default value of this component.

socketpair

Uses a connected pair of sockets.

Note that currently only the pipe connection type allows the normal and error output streams of the process to be separated.


Next: , Previous: , Up: Processes   [Contents][Index]