Previous Up Next

Chapter 21  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";;.

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.
Windows:   The Cygwin port of Objective Caml fully implements all functions from the Unix module. The native Win32 ports implement a subset of them. Below is a list of the functions that are not implemented, or only partially implemented, by the Win32 ports. Functions not mentioned are fully 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
in_channel_of_descrdoes not work on sockets under Windows 95, 98, ME; works fine under NT, 2000, XP
out_channel_of_descrditto
truncate, ftruncatenot implemented
lstat, fstatnot implemented
link, symlink, readlinknot implemented (no links under Windows)
fchmodnot implemented
chown, fchownnot implemented (make no sense on a DOS file system)
umasknot implemented
set_nonblock, clear_nonblockimplemented as dummy functions; use threads instead of non-blocking I/O
rewinddirnot implemented; re-open the directory instead
mkfifonot implemented
selectimplemented, but works only for sockets; use threads if you need to wait on other kinds of file descriptors
lockfnot implemented
kill, pausenot implemented (no inter-process signals in Windows)
alarm, timesnot implemented
getitimer, setitimernot implemented
getuid, getgidalways return 1
getgid, getegid, getgroupsnot implemented
setuid, setgidnot implemented
getpwnam, getpwuidalways raise Not_found
getgrnam, getgrgidalways raise Not_found
type socket_domainthe domain PF_UNIX is not supported; PF_INET is fully supported
open_connectiondoes not work under Windows 95, 98, ME; works fine under NT, 2000, XP
establish_servernot implemented; use threads
terminal functions (tc*)not implemented

Previous Up Next