This package contains utilities for process creation.
A process is represented by a process reference, a ground
compound term. Both SICStus and the operating system maintain a
state for each such process reference and they must therefore be
released, either explicitly with
process_wait/[2,3]. Process references are
process_create/[2,3] if explicitly requested with
process/1 option. Process references are required in
order to obtain the exit status of a process. Many of the
predicates can accept a numeric operating system process id
(“PID”) but since process ids are subject to re-use by the OS
this is less reliable and does not work if the process has already
Run ls on a home directory in a subshell under UNIX:
| ?- absolute_file_name('$SHELL', Shell), absolute_file_name('~/', Dir), process_create(Shell, ['-c', [ ls, ' ', file(Dir) ]]).
Run notepad.exe on a file C:/foo.txt under Windows:
| ?- absolute_file_name('$SYSTEMROOT/notepad.exe', Prog), process_create(Prog, [file('C:/foo.txt')]).
File, is expanded as if by
is used to locate the file to execute.
The predefined file search path
path/1 (see ref-fdi)
is especially useful here since it makes it easy to look up the
names of an executable in the directories mentioned by the
PATH environment variable. To run the Windows command shell
cmd you would simply specify
start the UNIX Bash shell you would specify
Args is a list of argument specifications. Each argument specification is either a simple argument specification, see below, or a non-empty list of simple argument specifications. The expanded value of each element of Args is concatenated to produce a single argument to the new process. A simple argument specification can be one of:
)is not subject to syntactic rewriting, the argument specification
file/1only adjusts for differences in file name syntax and character encoding between SICStus and the operating system. You must explicitly call
absolute_file_name/[2,3]if you want to expand file search paths etc.
pipe/1spec, see below, and explicitly read (write) data from (to) the process.
close/[1,2], it is not closed automatically when the new process exits.
process_wait/[2,3]etc.. This process reference must be released, either explicitly with
process_release/1or implicitly by
false. Specifies whether the new process should be “detached”, i.e. whether it should be notified of terminal events such as ^C interrupts. By default a new process is created detached if none of the standard streams are specified, explicitly or implicitly, as
absolute_file_name/2and is used as the working directory for the new process.
By default, the working directory is the same as the Prolog
false(the default). Specifies whether the process should open in its own window.
window(true) may give unexpected results if the
standard stream options
stderr/1 are specified with anything but their default
Currently only implemented on Windows.
=VALUE for extra environment variables to pass to the sub-process in addition to the default process environment. VAR and VALUE should be atoms. See System Properties and Environment Variables, for more information.
Process is either a process reference obtained from
process_create/3 or an OS process identifier. Specifying a
process identifier is not reliable. The process identifier may
have been re-used by the operating system. Under Windows, it is not
possible to obtain the exit status using a process identifier if
the process has already exited.
ExitStatus is one of:
SignalNumber(a positive integer).
timeout/1option was specified and the process did not exit within the specified interval. In this case the process reference is not released, even if the
release/1option is specified.
infinite(the default) to specify infinite wait. If the specified timeout interval passes before the process exits,
process_wait/3exits with ExitStatus set to
timeoutand the process reference is not released.
Currently the UNIX implementation supports only timeout values
0 (zero) and
true(the default) or
false. Specifies whether the process reference should be released when
process_create/3. This ensures that Prolog and the operating system can reclaim any resources associated with the process reference.
Usually you would not call this. Either do not request the process
reference when calling
process_create/3 or let
process_wait/[2,3] reclaim the process reference when the
The following signal names are accepted under UNIX if the platform
SIGKILL (the default),
SIGXFSZ. However, many of these do not
make sense to send as signals.
Under Windows, which does not have the signal
concept, the signal name
SIGKILL (the default) is treated
specially and terminates the process with
Please note: Using
process_kill/[2,3] on Windows
is not recommended. Also, on Windows, the call may throw an error
if the process has already exited.