1<!DOCTYPE html> 2<html> 3<head> 4<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> 5<meta name="generator" content="hevea 2.18"> 6<link rel="stylesheet" type="text/css" href="manual.css"> 7<title>Chapter 26  The unix library: Unix system calls</title> 8</head> 9<body> 10<a href="parsing.html"><img src="previous_motif.gif" alt="Previous"></a> 11<a href="index.html"><img src="contents_motif.gif" alt="Up"></a> 12<a href="libnum.html"><img src="next_motif.gif" alt="Next"></a> 13<hr> 14<h1 class="chapter" id="sec532">Chapter 26  The unix library: Unix system calls</h1> 15<p>The <span class="c003">unix</span> library makes many Unix 16system calls and system-related library functions available to 17OCaml programs. This chapter describes briefly the functions 18provided. Refer to sections 2 and 3 of the Unix manual for more 19details on the behavior of these functions.</p><p>Not all functions are provided by all Unix variants. If some functions 20are not available, they will raise <span class="c003">Invalid_arg</span> when called.</p><p>Programs that use the <span class="c003">unix</span> library must be linked as follows: 21</p><pre> 22 ocamlc <span class="c009">other options</span> unix.cma <span class="c009">other files</span> 23 ocamlopt <span class="c009">other options</span> unix.cmxa <span class="c009">other files</span> 24</pre><p> 25For interactive use of the <span class="c003">unix</span> library, do: 26</p><pre> 27 ocamlmktop -o mytop unix.cma 28 ./mytop 29</pre><p> 30or (if dynamic linking of C libraries is supported on your platform), 31start <span class="c003">ocaml</span> and type <span class="c003">#load "unix.cma";;</span>.</p><blockquote class="quote"><span class="c007">Windows:</span>   32A fairly complete emulation of the Unix system calls is provided in 33the Windows version of OCaml. The end of this chapter gives 34more information on the functions that are not supported under Windows. 35</blockquote><ul class="ftoc2"><li class="li-links"> 36<a href="libref/Unix.html">Module <span class="c003">Unix</span>: Unix system calls</a> 37</li><li class="li-links"><a href="libref/UnixLabels.html">Module <span class="c003">UnixLabels</span>: Labeled 38Unix system calls</a> 39</li></ul><blockquote class="quote"><span class="c007">Windows:</span>   40The Cygwin port of OCaml fully implements all functions from 41the Unix module. The native Win32 ports implement a subset of them. 42Below is a list of the functions that are not implemented, or only 43partially implemented, by the Win32 ports. Functions not mentioned are 44fully implemented and behave as described previously in this chapter.<div class="center"><table class="c000 cellpadding1" border=1><tr><td class="c014"><span class="c013">Functions</span></td><td class="c014"><span class="c013">Comment</span> </td></tr> 45<tr><td class="c022"> 46<span class="c003">fork</span></td><td class="c021">not implemented, use <span class="c003">create_process</span> or threads </td></tr> 47<tr><td class="c022"><span class="c003">wait</span></td><td class="c021">not implemented, use <span class="c003">waitpid</span> </td></tr> 48<tr><td class="c022"><span class="c003">waitpid</span></td><td class="c021">can only wait for a given PID, not any child process </td></tr> 49<tr><td class="c022"><span class="c003">getppid</span></td><td class="c021">not implemented (meaningless under Windows) </td></tr> 50<tr><td class="c022"><span class="c003">nice</span></td><td class="c021">not implemented </td></tr> 51<tr><td class="c022"><span class="c003">truncate</span>, <span class="c003">ftruncate</span></td><td class="c021">not implemented </td></tr> 52<tr><td class="c022"><span class="c003">link</span></td><td class="c021">implemented (since 3.02) </td></tr> 53<tr><td class="c022"><span class="c003">symlink</span>, <span class="c003">readlink</span></td><td class="c021">implemented (since 4.03.0) </td></tr> 54<tr><td class="c022"><span class="c003">access</span></td><td class="c021">execute permission <span class="c003">X_OK</span> cannot be tested, 55it just tests for read permission instead </td></tr> 56<tr><td class="c022"><span class="c003">fchmod</span></td><td class="c021">not implemented </td></tr> 57<tr><td class="c022"><span class="c003">chown</span>, <span class="c003">fchown</span></td><td class="c021">not implemented (make no sense on a DOS 58file system) </td></tr> 59<tr><td class="c022"><span class="c003">umask</span></td><td class="c021">not implemented </td></tr> 60<tr><td class="c022"><span class="c003">mkfifo</span></td><td class="c021">not implemented </td></tr> 61<tr><td class="c022"><span class="c003">kill</span></td><td class="c021">partially implemented (since 4.00.0): only the <span class="c003">sigkill</span> signal 62is implemented </td></tr> 63<tr><td class="c022"><span class="c003">pause</span></td><td class="c021">not implemented (no inter-process signals in Windows) </td></tr> 64<tr><td class="c022"><span class="c003">alarm</span></td><td class="c021">not implemented </td></tr> 65<tr><td class="c022"><span class="c003">times</span></td><td class="c021">partially implemented, will not report timings for child 66processes </td></tr> 67<tr><td class="c022"><span class="c003">getitimer</span>, <span class="c003">setitimer</span></td><td class="c021">not implemented </td></tr> 68<tr><td class="c022"><span class="c003">getuid</span>, <span class="c003">geteuid</span>, <span class="c003">getgid</span>, <span class="c003">getegid</span></td><td class="c021">always return 1 </td></tr> 69<tr><td class="c022"><span class="c003">getgroups</span></td><td class="c021">always returns <span class="c003">[|1|]</span> (since 2.00) </td></tr> 70<tr><td class="c022"><span class="c003">setuid</span>, <span class="c003">setgid</span>, <span class="c003">setgroups</span></td><td class="c021">not implemented </td></tr> 71<tr><td class="c022"><span class="c003">getpwnam</span>, <span class="c003">getpwuid</span></td><td class="c021">always raise <span class="c003">Not_found</span> </td></tr> 72<tr><td class="c022"><span class="c003">getgrnam</span>, <span class="c003">getgrgid</span></td><td class="c021">always raise <span class="c003">Not_found</span> </td></tr> 73<tr><td class="c022">type <span class="c003">socket_domain</span></td><td class="c021"><span class="c003">PF_INET</span> is fully supported; 74<span class="c003">PF_INET6</span> is fully supported (since 4.01.0); <span class="c003">PF_UNIX</span> is not supported </td></tr> 75<tr><td class="c022"><span class="c003">establish_server</span></td><td class="c021">not implemented; use threads </td></tr> 76<tr><td class="c022">terminal functions (<span class="c003">tc*</span>)</td><td class="c021">not implemented </td></tr> 77</table></div></blockquote> 78<hr> 79<a href="parsing.html"><img src="previous_motif.gif" alt="Previous"></a> 80<a href="index.html"><img src="contents_motif.gif" alt="Up"></a> 81<a href="libnum.html"><img src="next_motif.gif" alt="Next"></a> 82</body> 83</html> 84