This library offers predicates to create, communicate, and synchronize with child processes. The child processes are duplicates of the parent process, based on the fork() function from POSIX-compatible operating systems (see man page for a precise description of the non-inherited process attributes).
The child process can execute a given goal (in a clone of the parent process) or start an external program.
Contrary to threads, processes have a separate address space and communication must be performed via inter-process communication mechanisms. This is useful for executing external programs, or implementing coarse-grained parallelism and concurrency.
A process handler
The predicate process_call/3 waits for process completion, throwing an exception if the return code is different than 0. This default exit behaviour can be controlled with the following options:
The process standard input, output, and error file descriptors (streams from the Prolog side) can be bound to several process_channel/1:
The environment of the process can be modified with the following options:
Options that control command execution
Execute a command in a child process, where Cmd is the executable path. Use path(Exec) for executing a program Exec reachable from the PATH environment variable
The process has already been joined.
Wait for completion of process Process.
Sends POSIX signal SIGTERM to the process Process, which asks politely for process termination.
Sends POSIX signal SIGKILL to the process Process, which forces process termination.
Execute Goal in a forked process.
Execute the list Cmds of process_call/3, connecting standard input and output of consecutive processes with pipes.
Options are passed as follows: input redirection options are applied to the first process; output redirection and status are applied to the last process; the rest of options are applied to all commands. Background execution is not currently supported (see internal documentation for details).