[det]fork(-Pid)Clone the current process into two branches. In the child, Pid
is unified to child. In the original process, Pid is unified
to the process identifier of the created child. Both parent and child
are fully functional Prolog processes running the same program. The
processes share open I/O streams that refer to Unix native streams, such
as files, sockets and pipes. Data is not shared, though on most Unix
systems data is initially shared and duplicated only if one of the
programs attempts to modify the data.
Unix fork()
is the only way to create new processes and fork/1
is a simple direct interface to it.
- Errors
permission_error(fork, process, main)
is raised if the
calling thread is not the only thread in the process. Forking a Prolog
process with threads will typically deadlock because only the calling
thread is cloned in the fork, while all thread synchronization are
cloned.