Chapter 25 The unix library: Unix system calls

The unix library makes many Unixsystem calls and system-related library functions available toOCaml programs. This chapter describes briefly the functionsprovided. Refer to sections 2 and 3 of the Unix manual for moredetails on the behavior of these functions.

Programs that use the unix library must be linked as follows:

  1. ocamlc other options unix.cma other files
  2. ocamlopt other options unix.cmxa other files

For interactive use of the unix library, do:

  1. ocamlmktop -o mytop unix.cma
  2. ./mytop

or (if dynamic linking of C libraries is supported on your platform),start ocaml and type #load "unix.cma";;.

Windows:A fairly complete emulation of the Unix system calls is provided inthe Windows version of OCaml. The end of this chapter givesmore information on the functions that are not supported under Windows.
Windows:The Cygwin port of OCaml fully implements all functions fromthe Unix module. The native Win32 ports implement a subset of them.Below is a list of the functions that are not implemented, or onlypartially implemented, by the Win32 ports. Functions not mentioned arefully implemented and behave as described previously in this chapter.
FunctionsComment
forknot implemented, use create_process or threads
waitnot implemented, use waitpid
waitpidcan only wait for a given PID, not any child process
getppidnot implemented (meaningless under Windows)
nicenot implemented
truncate, ftruncatenot implemented
linkimplemented (since 3.02)
symlink, readlinkimplemented (since 4.03.0)
accessexecute permission X_OK cannot be tested,it just tests for read permission instead
fchmodnot implemented
chown, fchownnot implemented (make no sense on a DOSfile system)
umasknot implemented
mkfifonot implemented
killpartially implemented (since 4.00.0): only the sigkill signalis implemented
pausenot implemented (no inter-process signals in Windows)
alarmnot implemented
timespartially implemented, will not report timings for childprocesses
getitimer, setitimernot implemented
getuid, geteuid, getgid, getegidalways return 1
getgroupsalways returns [|1|] (since 2.00)
setuid, setgid, setgroupsnot implemented
getpwnam, getpwuidalways raise Not_found
getgrnam, getgrgidalways raise Not_found
type socket_domainPF_INET is fully supported;PF_INET6 is fully supported (since 4.01.0); PF_UNIX is not supported
establish_servernot implemented; use threads
terminal functions (tc*)not implemented