PublicShow sourceunix.pl -- Unix specific operations

The library(unix) library provides the commonly used Unix primitives to deal with process management. These primitives are useful for many tasks, including server management, parallel computation, exploiting and controlling other processes, etc.

The predicates in this library are modelled closely after their native Unix counterparts.

See also
- library(process) provides a portable high level interface to create and manage processes.
Source fork(-Pid) is det
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.

Undocumented predicates

The following predicates are exported, but not or incorrectly documented.

Source detach_IO(Arg1)
Source environ(Arg1)
Source dup(Arg1, Arg2)
Source fork_exec(Arg1)
Source kill(Arg1, Arg2)
Source wait(Arg1, Arg2)
Source pipe(Arg1, Arg2)
Source detach_IO
Source sysconf(Arg1)
Source exec(Arg1)
Source prctl(Arg1)