Previous Contents Next
Chapter 20 The unix library: Unix system calls

The unix library makes many Unix system calls and system-related library functions available to Objective Caml programs. This chapter describes briefly the functions provided. Refer to sections 2 and 3 of the Unix manual for more details on the behavior of these functions.

Not all functions are provided by all Unix variants. If some functions are not available, they will raise Invalid_arg when called.

Programs that use the unix library must be linked as follows:
        ocamlc other options unix.cma other files
        ocamlopt other options unix.cmxa other files
For interactive use of the unix library, do:
        ocamlmktop -o mytop unix.cma
        ./mytop
or (if dynamic linking of C libraries is supported on your platform), start ocaml and type #load "unix.cma";;.

  MacOS:
A fairly complete emulation of the Unix system calls is provided in the MacOS version of Objective Caml. The end of this chapter gives more information on the functions that are not supported under MacOS.
  Windows:
A fairly complete emulation of the Unix system calls is provided in the Windows version of Objective Caml. The end of this chapter gives more information on the functions that are not supported under Windows.
20.1 Module Unix: interface to the Unix system


Error report
type error =
Errors defined in the POSIX standard
    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