Raised by the system calls below when an error is encountered.
The first component is the error code; the second component
is the function name; the third component is the string parameter
to the function, if it has one, or the empty string otherwise.

execv prog args execute the program in file prog, with
the arguments args, and the current process environment.
These execv* functions never return: on success, the current
program is replaced by the new one;
on failure, a UnixLabels.Unix_error exception is raised.

Same as UnixLabels.wait, but waits for the child process whose pid is given.
A pid of -1 means wait for any child.
A pid of 0 means wait for any child in the same process group
as the current process.
Negative pid arguments represent process groups.
The list of options indicates whether waitpid should return
immediately without waiting, or also report stopped children.

Execute the given command, wait until it terminates, and return
its termination status. The string is interpreted by the shell
/bin/sh and therefore can contain redirections, quotes, variables,
etc. The result WEXITED 127 indicates that the shell couldn't
be executed.

val getpid : unit -> int

Return the pid of the process.

val getppid : unit -> int

Return the pid of the parent process.

val nice : int -> int

Change the process priority. The integer argument is added to the
``nice'' value. (Higher values of the ``nice'' value mean
lower priorities.) Return the new nice value.

write fd buff ofs len writes len characters to descriptor
fd, taking them from string buff, starting at position ofs
in string buff. Return the number of characters actually
written. write repeats the writing operation until all characters
have been written or an error occurs.

Set the ``non-blocking'' flag on the given descriptor.
When the non-blocking flag is set, reading on a descriptor
on which there is temporarily no data available raises the
EAGAIN or EWOULDBLOCK error instead of blocking;
writing on a descriptor on which there is temporarily no room
for writing also raises EAGAIN or EWOULDBLOCK.

High-level process and redirection management

create_process prog args new_stdin new_stdout new_stderr
forks a new process that executes the program
in file prog, with arguments args. The pid of the new
process is returned immediately; the new process executes
concurrently with the current process.
The standard input and outputs of the new process are connected
to the descriptors new_stdin, new_stdout and new_stderr.
Passing e.g. stdout for new_stdout prevents the redirection
and causes the new process to have the same standard output
as the current process.
The executable file prog is searched in the path.
The new process has the same environment as the current process.

High-level pipe and process management. This function
runs the given command in parallel with the program.
The standard output of the command is redirected to a pipe,
which can be read via the returned input channel.
The command is interpreted by the shell /bin/sh (cf. system).

Same as UnixLabels.open_process_in, but redirect the standard input of
the command to a pipe. Data written to the returned output channel
is sent to the standard input of the command.
Warning: writes on output channels are buffered, hence be careful
to call flush at the right times to ensure
correct synchronization.

Same as UnixLabels.open_process_out, but redirects both the standard
input and standard output of the command to pipes connected to the two
returned channels. The input channel is connected to the output
of the command, and the output channel to the input of the command.

Similar to UnixLabels.open_process, but the second argument specifies
the environment passed to the command. The result is a triple
of channels connected respectively to the standard output, standard input,
and standard error of the command.

Polling

Wait until some input/output operations become possible on
some channels. The three list arguments are, respectively, a set
of descriptors to check for reading (first argument), for writing
(second argument), or for exceptional conditions (third argument).
The fourth argument is the maximal timeout, in seconds; a
negative fourth argument means no timeout (unbounded wait).
The result is composed of three sets of descriptors: those ready
for reading (first component), ready for writing (second component),
and over which an exceptional condition is pending (third
component).

lockf fd cmd size puts a lock on a region of the file opened
as fd. The region starts at the current read/write position for
fd (as set by UnixLabels.lseek), and extends size bytes forward if
size is positive, size bytes backwards if size is negative,
or to the end of the file if size is zero.
A write lock prevents any other
process from acquiring a read or write lock on the region.
A read lock prevents any other
process from acquiring a write lock on the region, but lets
other processes acquire read locks on it.

The F_LOCK and F_TLOCK commands attempts to put a write lock
on the specified region.
The F_RLOCK and F_TRLOCK commands attempts to put a read lock
on the specified region.
If one or several locks put by another process prevent the current process
from acquiring the lock, F_LOCK and F_RLOCK block until these locks
are removed, while F_TLOCK and F_TRLOCK fail immediately with an
exception.
The F_ULOCK removes whatever locks the current process has on
the specified region.
Finally, the F_TEST command tests whether a write lock can be
acquired on the specified region, without actually putting a lock.
It returns immediately if successful, or fails otherwise.

sigprocmask cmd sigs changes the set of blocked signals.
If cmd is SIG_SETMASK, blocked signals are set to those in
the list sigs.
If cmd is SIG_BLOCK, the signals in sigs are added to
the set of blocked signals.
If cmd is SIG_UNBLOCK, the signals in sigs are removed
from the set of blocked signals.
sigprocmask returns the set of previously blocked signals.

val sigpending : unit -> int list

Return the set of blocked signals that are currently pending.

val sigsuspend : int list -> unit

sigsuspend sigs atomically sets the blocked signals to sigs
and waits for a non-ignored, non-blocked signal to be delivered.
On return, the blocked signals are reset to their initial value.

Convert a date and time, specified by the tm argument, into
a time in seconds, as returned by UnixLabels.time. The tm_isdst,
tm_wday and tm_yday fields of tm are ignored. Also return a
normalized copy of the given tm record, with the tm_wday,
tm_yday, and tm_isdst fields recomputed from the other fields,
and the other fields normalized (so that, e.g., 40 October is
changed into 9 November). The tm argument is interpreted in the
local time zone.

Set the last access time (second arg) and last modification time
(third arg) for a file. Times are expressed in seconds from
00:00:00 GMT, Jan. 1, 1970. A time of 0.0 is interpreted as the
current time.

setitimer t s sets the interval timer t and returns
its previous status. The s argument is interpreted as follows:
s.it_value, if nonzero, is the time to the next timer expiration;
s.it_interval, if nonzero, specifies a value to
be used in reloading it_value when the timer expires.
Setting s.it_value to zero disable the timer.
Setting s.it_interval to zero causes the timer to be disabled
after its next expiration.

User id, group id

val getuid : unit -> int

Return the user id of the user executing the process.

val geteuid : unit -> int

Return the effective user id under which the process runs.

val setuid : int -> unit

Set the real user id and effective user id for the process.

val getgid : unit -> int

Return the group id of the user executing the process.

val getegid : unit -> int

Return the effective group id under which the process runs.

val setgid : int -> unit

Set the real group id and effective group id for the process.

val getgroups : unit -> int array

Return the list of groups to which the user executing the process
belongs.

val setgroups : int array -> unit

setgroups groups sets the supplementary group IDs for the
calling process. Appropriate privileges are required.

val initgroups : string -> int -> unit

initgroups user group initializes the group access list by
reading the group database /etc/group and using all groups of
which user is a member. The additional group group is also
added to the list.

Internet addresses

Conversion from the printable representation of an Internet
address to its internal representation. The argument string
consists of 4 numbers separated by periods (XXX.YYY.ZZZ.TTT)
for IPv4 addresses, and up to 8 numbers separated by colons
for IPv6 addresses. Raise Failure when given a string that
does not match these formats.

The type of socket addresses. ADDR_UNIX name is a socket
address in the Unix domain; name is a file name in the file
system. ADDR_INET(addr,port) is a socket address in the Internet
domain; addr is the Internet address of the machine, and
port is the port number.

Shutdown a socket connection. SHUTDOWN_SEND as second argument
causes reads on the other end of the connection to return
an end-of-file condition.
SHUTDOWN_RECEIVE causes writes on the other end of the connection
to return a closed pipe condition (SIGPIPE signal).

Establish a server on the given address.
The function given as first argument is called for each connection
with two buffered channels connected to the client. A new process
is created for each connection. The function UnixLabels.establish_server
never returns normally.

getaddrinfo host service opts returns a list of Unix.addr_info
records describing socket parameters and addresses suitable for
communicating with the given host and service. The empty list is
returned if the host or service names are unknown, or the constraints
expressed in opts cannot be satisfied.

host is either a host name or the string representation of an IP
address. host can be given as the empty string; in this case,
the ``any'' address or the ``loopback'' address are used,
depending whether opts contains AI_PASSIVE.
service is either a service name or the string representation of
a port number. service can be given as the empty string;
in this case, the port field of the returned addresses is set to 0.
opts is a possibly empty list of options that allows the caller
to force a particular socket domain (e.g. IPv6 only or IPv4 only)
or a particular socket type (e.g. TCP only or UDP only).

getnameinfo addr opts returns the host name and service name
corresponding to the socket address addr. opts is a possibly
empty list of options that governs how these names are obtained.
Raise Not_found if an error occurs.

Terminal interface

The following functions implement the POSIX standard terminal
interface. They provide control over asynchronous communication ports
and pseudo-terminals. Refer to the termios man page for a
complete description.

Set the status of the terminal referred to by the given
file descriptor. The second argument indicates when the
status change takes place: immediately (TCSANOW),
when all pending output has been transmitted (TCSADRAIN),
or after flushing all input that has been received but not
read (TCSAFLUSH). TCSADRAIN is recommended when changing
the output parameters; TCSAFLUSH, when changing the input
parameters.

Discard data written on the given file descriptor but not yet
transmitted, or data received but not yet read, depending on the
second argument: TCIFLUSH flushes data received but not read,
TCOFLUSH flushes data written but not transmitted, and
TCIOFLUSH flushes both.

Suspend or restart reception or transmission of data on
the given file descriptor, depending on the second argument:
TCOOFF suspends output, TCOON restarts output,
TCIOFF transmits a STOP character to suspend input,
and TCION transmits a START character to restart input.

val setsid : unit -> int

Put the calling process in a new session and detach it from
its controlling terminal.