- Error report
- Access to the process environment
- Process handling
- Basic file input/output
- Interfacing with the standard input/output library
- Seeking and truncating
- File status
- File operations on large files
- Mapping files into memory
- Operations on file names
- File permissions and ownership
- Operations on file descriptors
- Directories
- Pipes and redirections
- High-level process and redirection management
- Symbolic links
- Polling
- Locking
- Signals
- Time functions
- User id, group id
- Internet addresses
- Sockets
- Socket options
- High-level network connection functions
- Host and protocol databases
- Terminal interface
-
bigarray
-
dynlink
-
ocamlbytecomp
-
ocamlcommon
-
ocamlmiddleend
-
ocamloptcomp
-
odoc_info
-
stdlib
-
str
-
unix
Library
Module
Module type
Parameter
Class
Class type
Interface to the Unix system.
To use the labeled version of this module, add module Unix
=
UnixLabels
in your implementation.
Note: all the functions of this module (except error_message
and handle_unix_error
) are liable to raise the Unix_error
exception whenever the underlying system call signals an error.
Error report
type error = Unix.error =
| E2BIG
(*Argument list too long
*)| EACCES
(*Permission denied
*)| EAGAIN
(*Resource temporarily unavailable; try again
*)| EBADF
(*Bad file descriptor
*)| EBUSY
(*Resource unavailable
*)| ECHILD
(*No child process
*)| EDEADLK
(*Resource deadlock would occur
*)| EDOM
(*Domain error for math functions, etc.
*)| EEXIST
(*File exists
*)| EFAULT
(*Bad address
*)| EFBIG
(*File too large
*)| EINTR
(*Function interrupted by signal
*)| EINVAL
(*Invalid argument
*)| EIO
(*Hardware I/O error
*)| EISDIR
(*Is a directory
*)| EMFILE
(*Too many open files by the process
*)| EMLINK
(*Too many links
*)| ENAMETOOLONG
(*Filename too long
*)| ENFILE
(*Too many open files in the system
*)| ENODEV
(*No such device
*)| ENOENT
(*No such file or directory
*)| ENOEXEC
(*Not an executable file
*)| ENOLCK
(*No locks available
*)| ENOMEM
(*Not enough memory
*)| ENOSPC
(*No space left on device
*)| ENOSYS
(*Function not supported
*)| ENOTDIR
(*Not a directory
*)| ENOTEMPTY
(*Directory not empty
*)| ENOTTY
(*Inappropriate I/O control operation
*)| ENXIO
(*No such device or address
*)| EPERM
(*Operation not permitted
*)| EPIPE
(*Broken pipe
*)| ERANGE
(*Result too large
*)| EROFS
(*Read-only file system
*)| ESPIPE
(*Invalid seek e.g. on a pipe
*)| ESRCH
(*No such process
*)| EXDEV
(*Invalid link
*)| EWOULDBLOCK
(*Operation would block
*)| EINPROGRESS
(*Operation now in progress
*)| EALREADY
(*Operation already in progress
*)| ENOTSOCK
(*Socket operation on non-socket
*)| EDESTADDRREQ
(*Destination address required
*)| EMSGSIZE
(*Message too long
*)| EPROTOTYPE
(*Protocol wrong type for socket
*)| ENOPROTOOPT
(*Protocol not available
*)| EPROTONOSUPPORT
(*Protocol not supported
*)| ESOCKTNOSUPPORT
(*Socket type not supported
*)| EOPNOTSUPP
(*Operation not supported on socket
*)| EPFNOSUPPORT
(*Protocol family not supported
*)| EAFNOSUPPORT
(*Address family not supported by protocol family
*)| EADDRINUSE
(*Address already in use
*)| EADDRNOTAVAIL
(*Can't assign requested address
*)| ENETDOWN
(*Network is down
*)| ENETUNREACH
(*Network is unreachable
*)| ENETRESET
(*Network dropped connection on reset
*)| ECONNABORTED
(*Software caused connection abort
*)| ECONNRESET
(*Connection reset by peer
*)| ENOBUFS
(*No buffer space available
*)| EISCONN
(*Socket is already connected
*)| ENOTCONN
(*Socket is not connected
*)| ESHUTDOWN
(*Can't send after socket shutdown
*)| ETOOMANYREFS
(*Too many references: can't splice
*)| ETIMEDOUT
(*Connection timed out
*)| ECONNREFUSED
(*Connection refused
*)| EHOSTDOWN
(*Host is down
*)| EHOSTUNREACH
(*No route to host
*)| ELOOP
(*Too many levels of symbolic links
*)| EOVERFLOW
(*File size or position not representable
*)| EUNKNOWNERR of int
(*Unknown error
*)
The type of error codes. Errors defined in the POSIX standard and additional errors from UNIX98 and BSD. All other errors are mapped to EUNKNOWNERR.
exception Unix_error of error * string * string
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.
UnixLabels.Unix_error
and Unix.Unix_error
are the same, and catching one will catch the other.
val error_message : error -> string
Return a string describing the given error code.
handle_unix_error f x
applies f
to x
and returns the result. If the exception Unix_error
is raised, it prints a message describing the error and exits with code 2.
Access to the process environment
Return the process environment, as an array of strings with the format ``variable=value''. The returned array is empty if the process has special privileges.
Return the process environment, as an array of strings with the format ``variable=value''. Unlike environment
, this function returns a populated array even if the process has special privileges. See the documentation for unsafe_getenv
for more details.
- since 4.12.0
Return the value associated to a variable in the process environment, unless the process has special privileges.
- raises Not_found
if the variable is unbound or the process has special privileges.
This function is identical to
Sys.getenv
.
Return the value associated to a variable in the process environment.
Unlike getenv
, this function returns the value even if the process has special privileges. It is considered unsafe because the programmer of a setuid or setgid program must be careful to avoid using maliciously crafted environment variables in the search path for executables, the locations for temporary files or logs, and the like.
- raises Not_found
if the variable is unbound.
- since 4.06.0
putenv name value
sets the value associated to a variable in the process environment. name
is the name of the environment variable, and value
its new associated value.
Process handling
type process_status = Unix.process_status =
The termination status of a process. See module Sys
for the definitions of the standard signal numbers. Note that they are not the numbers used by the OS.
type wait_flag = Unix.wait_flag =
Flags for waitpid
.
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.
- raises Unix_error
on failure
Same as execv
, except that the third argument provides the environment to the program executed.
Same as execv
, except that the program is searched in the path.
Same as execve
, except that the program is searched in the path.
Fork a new process. The returned integer is 0 for the child process, the pid of the child process for the parent process.
- raises Invalid_argument
on Windows. Use
create_process
or threads instead.
val wait : unit -> int * process_status
Wait until one of the children processes die, and return its pid and termination status.
- raises Invalid_argument
on Windows. Use
waitpid
instead.
val waitpid : mode:wait_flag list -> int -> int * process_status