Add copyright notices and new function String.chomp
[ocaml.git] / otherlibs / unix / unix.mli
blobacc0d74a49a6bb805d751a1b2023c02d6bc1ab37
1 (***********************************************************************)
2 (* *)
3 (* Objective Caml *)
4 (* *)
5 (* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
6 (* *)
7 (* Copyright 1996 Institut National de Recherche en Informatique et *)
8 (* en Automatique. All rights reserved. This file is distributed *)
9 (* under the terms of the GNU Library General Public License, with *)
10 (* the special exception on linking described in file ../../LICENSE. *)
11 (* *)
12 (***********************************************************************)
14 (* $Id$ *)
16 (** Interface to the Unix system *)
19 (** {6 Error report} *)
22 type error =
23 E2BIG (** Argument list too long *)
24 | EACCES (** Permission denied *)
25 | EAGAIN (** Resource temporarily unavailable; try again *)
26 | EBADF (** Bad file descriptor *)
27 | EBUSY (** Resource unavailable *)
28 | ECHILD (** No child process *)
29 | EDEADLK (** Resource deadlock would occur *)
30 | EDOM (** Domain error for math functions, etc. *)
31 | EEXIST (** File exists *)
32 | EFAULT (** Bad address *)
33 | EFBIG (** File too large *)
34 | EINTR (** Function interrupted by signal *)
35 | EINVAL (** Invalid argument *)
36 | EIO (** Hardware I/O error *)
37 | EISDIR (** Is a directory *)
38 | EMFILE (** Too many open files by the process *)
39 | EMLINK (** Too many links *)
40 | ENAMETOOLONG (** Filename too long *)
41 | ENFILE (** Too many open files in the system *)
42 | ENODEV (** No such device *)
43 | ENOENT (** No such file or directory *)
44 | ENOEXEC (** Not an executable file *)
45 | ENOLCK (** No locks available *)
46 | ENOMEM (** Not enough memory *)
47 | ENOSPC (** No space left on device *)
48 | ENOSYS (** Function not supported *)
49 | ENOTDIR (** Not a directory *)
50 | ENOTEMPTY (** Directory not empty *)
51 | ENOTTY (** Inappropriate I/O control operation *)
52 | ENXIO (** No such device or address *)
53 | EPERM (** Operation not permitted *)
54 | EPIPE (** Broken pipe *)
55 | ERANGE (** Result too large *)
56 | EROFS (** Read-only file system *)
57 | ESPIPE (** Invalid seek e.g. on a pipe *)
58 | ESRCH (** No such process *)
59 | EXDEV (** Invalid link *)
60 | EWOULDBLOCK (** Operation would block *)
61 | EINPROGRESS (** Operation now in progress *)
62 | EALREADY (** Operation already in progress *)
63 | ENOTSOCK (** Socket operation on non-socket *)
64 | EDESTADDRREQ (** Destination address required *)
65 | EMSGSIZE (** Message too long *)
66 | EPROTOTYPE (** Protocol wrong type for socket *)
67 | ENOPROTOOPT (** Protocol not available *)
68 | EPROTONOSUPPORT (** Protocol not supported *)
69 | ESOCKTNOSUPPORT (** Socket type not supported *)
70 | EOPNOTSUPP (** Operation not supported on socket *)
71 | EPFNOSUPPORT (** Protocol family not supported *)
72 | EAFNOSUPPORT (** Address family not supported by protocol family *)
73 | EADDRINUSE (** Address already in use *)
74 | EADDRNOTAVAIL (** Can't assign requested address *)
75 | ENETDOWN (** Network is down *)
76 | ENETUNREACH (** Network is unreachable *)
77 | ENETRESET (** Network dropped connection on reset *)
78 | ECONNABORTED (** Software caused connection abort *)
79 | ECONNRESET (** Connection reset by peer *)
80 | ENOBUFS (** No buffer space available *)
81 | EISCONN (** Socket is already connected *)
82 | ENOTCONN (** Socket is not connected *)
83 | ESHUTDOWN (** Can't send after socket shutdown *)
84 | ETOOMANYREFS (** Too many references: can't splice *)
85 | ETIMEDOUT (** Connection timed out *)
86 | ECONNREFUSED (** Connection refused *)
87 | EHOSTDOWN (** Host is down *)
88 | EHOSTUNREACH (** No route to host *)
89 | ELOOP (** Too many levels of symbolic links *)
90 | EOVERFLOW (** File size or position not representable *)
92 | EUNKNOWNERR of int (** Unknown error *)
93 (** The type of error codes.
94 Errors defined in the POSIX standard
95 and additional errors from UNIX98 and BSD.
96 All other errors are mapped to EUNKNOWNERR.
100 exception Unix_error of error * string * string
101 (** Raised by the system calls below when an error is encountered.
102 The first component is the error code; the second component
103 is the function name; the third component is the string parameter
104 to the function, if it has one, or the empty string otherwise. *)
106 val error_message : error -> string
107 (** Return a string describing the given error code. *)
109 val handle_unix_error : ('a -> 'b) -> 'a -> 'b
110 (** [handle_unix_error f x] applies [f] to [x] and returns the result.
111 If the exception [Unix_error] is raised, it prints a message
112 describing the error and exits with code 2. *)
115 (** {6 Access to the process environment} *)
118 val environment : unit -> string array
119 (** Return the process environment, as an array of strings
120 with the format ``variable=value''. *)
122 val getenv : string -> string
123 (** Return the value associated to a variable in the process
124 environment. Raise [Not_found] if the variable is unbound.
125 (This function is identical to [Sys.getenv].) *)
127 val putenv : string -> string -> unit
128 (** [Unix.putenv name value] sets the value associated to a
129 variable in the process environment.
130 [name] is the name of the environment variable,
131 and [value] its new associated value. *)
134 (** {6 Process handling} *)
137 type process_status =
138 WEXITED of int
139 (** The process terminated normally by [exit];
140 the argument is the return code. *)
141 | WSIGNALED of int
142 (** The process was killed by a signal;
143 the argument is the signal number. *)
144 | WSTOPPED of int
145 (** The process was stopped by a signal; the argument is the
146 signal number. *)
147 (** The termination status of a process. *)
150 type wait_flag =
151 WNOHANG (** do not block if no child has
152 died yet, but immediately return with a pid equal to 0.*)
153 | WUNTRACED (** report also the children that receive stop signals. *)
154 (** Flags for {!Unix.waitpid}. *)
156 val execv : string -> string array -> 'a
157 (** [execv prog args] execute the program in file [prog], with
158 the arguments [args], and the current process environment.
159 These [execv*] functions never return: on success, the current
160 program is replaced by the new one;
161 on failure, a {!Unix.Unix_error} exception is raised. *)
163 val execve : string -> string array -> string array -> 'a
164 (** Same as {!Unix.execv}, except that the third argument provides the
165 environment to the program executed. *)
167 val execvp : string -> string array -> 'a
168 (** Same as {!Unix.execv}, except that
169 the program is searched in the path. *)
171 val execvpe : string -> string array -> string array -> 'a
172 (** Same as {!Unix.execve}, except that
173 the program is searched in the path. *)
175 val fork : unit -> int
176 (** Fork a new process. The returned integer is 0 for the child
177 process, the pid of the child process for the parent process. *)
179 val wait : unit -> int * process_status
180 (** Wait until one of the children processes die, and return its pid
181 and termination status. *)
183 val waitpid : wait_flag list -> int -> int * process_status
184 (** Same as {!Unix.wait}, but waits for the child process whose pid is given.
185 A pid of [-1] means wait for any child.
186 A pid of [0] means wait for any child in the same process group
187 as the current process.
188 Negative pid arguments represent process groups.
189 The list of options indicates whether [waitpid] should return
190 immediately without waiting, or also report stopped children. *)
192 val system : string -> process_status
193 (** Execute the given command, wait until it terminates, and return
194 its termination status. The string is interpreted by the shell
195 [/bin/sh] and therefore can contain redirections, quotes, variables,
196 etc. The result [WEXITED 127] indicates that the shell couldn't
197 be executed. *)
199 val getpid : unit -> int
200 (** Return the pid of the process. *)
202 val getppid : unit -> int
203 (** Return the pid of the parent process. *)
205 val nice : int -> int
206 (** Change the process priority. The integer argument is added to the
207 ``nice'' value. (Higher values of the ``nice'' value mean
208 lower priorities.) Return the new nice value. *)
211 (** {6 Basic file input/output} *)
214 type file_descr
215 (** The abstract type of file descriptors. *)
217 val stdin : file_descr
218 (** File descriptor for standard input.*)
220 val stdout : file_descr
221 (** File descriptor for standard output.*)
223 val stderr : file_descr
224 (** File descriptor for standard error. *)
226 type open_flag =
227 O_RDONLY (** Open for reading *)
228 | O_WRONLY (** Open for writing *)
229 | O_RDWR (** Open for reading and writing *)
230 | O_NONBLOCK (** Open in non-blocking mode *)
231 | O_APPEND (** Open for append *)
232 | O_CREAT (** Create if nonexistent *)
233 | O_TRUNC (** Truncate to 0 length if existing *)
234 | O_EXCL (** Fail if existing *)
235 | O_NOCTTY (** Don't make this dev a controlling tty *)
236 | O_DSYNC (** Writes complete as `Synchronised I/O data integrity completion' *)
237 | O_SYNC (** Writes complete as `Synchronised I/O file integrity completion' *)
238 | O_RSYNC (** Reads complete as writes (depending on O_SYNC/O_DSYNC) *)
239 (** The flags to {!Unix.openfile}. *)
242 type file_perm = int
243 (** The type of file access rights, e.g. [0o640] is read and write for user,
244 read for group, none for others *)
246 val openfile : string -> open_flag list -> file_perm -> file_descr
247 (** Open the named file with the given flags. Third argument is
248 the permissions to give to the file if it is created. Return
249 a file descriptor on the named file. *)
251 val close : file_descr -> unit
252 (** Close a file descriptor. *)
254 val read : file_descr -> string -> int -> int -> int
255 (** [read fd buff ofs len] reads [len] characters from descriptor
256 [fd], storing them in string [buff], starting at position [ofs]
257 in string [buff]. Return the number of characters actually read. *)
259 val write : file_descr -> string -> int -> int -> int
260 (** [write fd buff ofs len] writes [len] characters to descriptor
261 [fd], taking them from string [buff], starting at position [ofs]
262 in string [buff]. Return the number of characters actually
263 written. [write] repeats the writing operation until all characters
264 have been written or an error occurs. *)
266 val single_write : file_descr -> string -> int -> int -> int
267 (** Same as [write], but attempts to write only once.
268 Thus, if an error occurs, [single_write] guarantees that no data
269 has been written. *)
271 (** {6 Interfacing with the standard input/output library} *)
275 val in_channel_of_descr : file_descr -> in_channel
276 (** Create an input channel reading from the given descriptor.
277 The channel is initially in binary mode; use
278 [set_binary_mode_in ic false] if text mode is desired. *)
280 val out_channel_of_descr : file_descr -> out_channel
281 (** Create an output channel writing on the given descriptor.
282 The channel is initially in binary mode; use
283 [set_binary_mode_out oc false] if text mode is desired. *)
285 val descr_of_in_channel : in_channel -> file_descr
286 (** Return the descriptor corresponding to an input channel. *)
288 val descr_of_out_channel : out_channel -> file_descr
289 (** Return the descriptor corresponding to an output channel. *)
292 (** {6 Seeking and truncating} *)
295 type seek_command =
296 SEEK_SET (** indicates positions relative to the beginning of the file *)
297 | SEEK_CUR (** indicates positions relative to the current position *)
298 | SEEK_END (** indicates positions relative to the end of the file *)
299 (** Positioning modes for {!Unix.lseek}. *)
302 val lseek : file_descr -> int -> seek_command -> int
303 (** Set the current position for a file descriptor *)
305 val truncate : string -> int -> unit
306 (** Truncates the named file to the given size. *)
308 val ftruncate : file_descr -> int -> unit
309 (** Truncates the file corresponding to the given descriptor
310 to the given size. *)
313 (** {6 File status} *)
316 type file_kind =
317 S_REG (** Regular file *)
318 | S_DIR (** Directory *)
319 | S_CHR (** Character device *)
320 | S_BLK (** Block device *)
321 | S_LNK (** Symbolic link *)
322 | S_FIFO (** Named pipe *)
323 | S_SOCK (** Socket *)
325 type stats =
326 { st_dev : int; (** Device number *)
327 st_ino : int; (** Inode number *)
328 st_kind : file_kind; (** Kind of the file *)
329 st_perm : file_perm; (** Access rights *)
330 st_nlink : int; (** Number of links *)
331 st_uid : int; (** User id of the owner *)
332 st_gid : int; (** Group ID of the file's group *)
333 st_rdev : int; (** Device minor number *)
334 st_size : int; (** Size in bytes *)
335 st_atime : float; (** Last access time *)
336 st_mtime : float; (** Last modification time *)
337 st_ctime : float; (** Last status change time *)
339 (** The informations returned by the {!Unix.stat} calls. *)
341 val stat : string -> stats
342 (** Return the information for the named file. *)
344 val lstat : string -> stats
345 (** Same as {!Unix.stat}, but in case the file is a symbolic link,
346 return the information for the link itself. *)
348 val fstat : file_descr -> stats
349 (** Return the information for the file associated with the given
350 descriptor. *)
352 val isatty : file_descr -> bool
353 (** Return [true] if the given file descriptor refers to a terminal or
354 console window, [false] otherwise. *)
356 (** {6 File operations on large files} *)
358 module LargeFile :
360 val lseek : file_descr -> int64 -> seek_command -> int64
361 val truncate : string -> int64 -> unit
362 val ftruncate : file_descr -> int64 -> unit
363 type stats =
364 { st_dev : int; (** Device number *)
365 st_ino : int; (** Inode number *)
366 st_kind : file_kind; (** Kind of the file *)
367 st_perm : file_perm; (** Access rights *)
368 st_nlink : int; (** Number of links *)
369 st_uid : int; (** User id of the owner *)
370 st_gid : int; (** Group ID of the file's group *)
371 st_rdev : int; (** Device minor number *)
372 st_size : int64; (** Size in bytes *)
373 st_atime : float; (** Last access time *)
374 st_mtime : float; (** Last modification time *)
375 st_ctime : float; (** Last status change time *)
377 val stat : string -> stats
378 val lstat : string -> stats
379 val fstat : file_descr -> stats
381 (** File operations on large files.
382 This sub-module provides 64-bit variants of the functions
383 {!Unix.lseek} (for positioning a file descriptor),
384 {!Unix.truncate} and {!Unix.ftruncate} (for changing the size of a file),
385 and {!Unix.stat}, {!Unix.lstat} and {!Unix.fstat} (for obtaining
386 information on files). These alternate functions represent
387 positions and sizes by 64-bit integers (type [int64]) instead of
388 regular integers (type [int]), thus allowing operating on files
389 whose sizes are greater than [max_int]. *)
392 (** {6 Operations on file names} *)
395 val unlink : string -> unit
396 (** Removes the named file *)
398 val rename : string -> string -> unit
399 (** [rename old new] changes the name of a file from [old] to [new]. *)
401 val link : string -> string -> unit
402 (** [link source dest] creates a hard link named [dest] to the file
403 named [source]. *)
406 (** {6 File permissions and ownership} *)
409 type access_permission =
410 R_OK (** Read permission *)
411 | W_OK (** Write permission *)
412 | X_OK (** Execution permission *)
413 | F_OK (** File exists *)
414 (** Flags for the {!Unix.access} call. *)
417 val chmod : string -> file_perm -> unit
418 (** Change the permissions of the named file. *)
420 val fchmod : file_descr -> file_perm -> unit
421 (** Change the permissions of an opened file. *)
423 val chown : string -> int -> int -> unit
424 (** Change the owner uid and owner gid of the named file. *)
426 val fchown : file_descr -> int -> int -> unit
427 (** Change the owner uid and owner gid of an opened file. *)
429 val umask : int -> int
430 (** Set the process's file mode creation mask, and return the previous
431 mask. *)
433 val access : string -> access_permission list -> unit
434 (** Check that the process has the given permissions over the named
435 file. Raise [Unix_error] otherwise. *)
438 (** {6 Operations on file descriptors} *)
441 val dup : file_descr -> file_descr
442 (** Return a new file descriptor referencing the same file as
443 the given descriptor. *)
445 val dup2 : file_descr -> file_descr -> unit
446 (** [dup2 fd1 fd2] duplicates [fd1] to [fd2], closing [fd2] if already
447 opened. *)
449 val set_nonblock : file_descr -> unit
450 (** Set the ``non-blocking'' flag on the given descriptor.
451 When the non-blocking flag is set, reading on a descriptor
452 on which there is temporarily no data available raises the
453 [EAGAIN] or [EWOULDBLOCK] error instead of blocking;
454 writing on a descriptor on which there is temporarily no room
455 for writing also raises [EAGAIN] or [EWOULDBLOCK]. *)
457 val clear_nonblock : file_descr -> unit
458 (** Clear the ``non-blocking'' flag on the given descriptor.
459 See {!Unix.set_nonblock}.*)
461 val set_close_on_exec : file_descr -> unit
462 (** Set the ``close-on-exec'' flag on the given descriptor.
463 A descriptor with the close-on-exec flag is automatically
464 closed when the current process starts another program with
465 one of the [exec] functions. *)
467 val clear_close_on_exec : file_descr -> unit
468 (** Clear the ``close-on-exec'' flag on the given descriptor.
469 See {!Unix.set_close_on_exec}.*)
472 (** {6 Directories} *)
475 val mkdir : string -> file_perm -> unit
476 (** Create a directory with the given permissions. *)
478 val rmdir : string -> unit
479 (** Remove an empty directory. *)
481 val chdir : string -> unit
482 (** Change the process working directory. *)
484 val getcwd : unit -> string
485 (** Return the name of the current working directory. *)
487 val chroot : string -> unit
488 (** Change the process root directory. *)
490 type dir_handle
491 (** The type of descriptors over opened directories. *)
493 val opendir : string -> dir_handle
494 (** Open a descriptor on a directory *)
496 val readdir : dir_handle -> string
497 (** Return the next entry in a directory.
498 @raise End_of_file when the end of the directory has been reached. *)
500 val rewinddir : dir_handle -> unit
501 (** Reposition the descriptor to the beginning of the directory *)
503 val closedir : dir_handle -> unit
504 (** Close a directory descriptor. *)
508 (** {6 Pipes and redirections} *)
511 val pipe : unit -> file_descr * file_descr
512 (** Create a pipe. The first component of the result is opened
513 for reading, that's the exit to the pipe. The second component is
514 opened for writing, that's the entrance to the pipe. *)
516 val mkfifo : string -> file_perm -> unit
517 (** Create a named pipe with the given permissions. *)
520 (** {6 High-level process and redirection management} *)
523 val create_process :
524 string -> string array -> file_descr -> file_descr -> file_descr -> int
525 (** [create_process prog args new_stdin new_stdout new_stderr]
526 forks a new process that executes the program
527 in file [prog], with arguments [args]. The pid of the new
528 process is returned immediately; the new process executes
529 concurrently with the current process.
530 The standard input and outputs of the new process are connected
531 to the descriptors [new_stdin], [new_stdout] and [new_stderr].
532 Passing e.g. [stdout] for [new_stdout] prevents the redirection
533 and causes the new process to have the same standard output
534 as the current process.
535 The executable file [prog] is searched in the path.
536 The new process has the same environment as the current process. *)
538 val create_process_env :
539 string -> string array -> string array -> file_descr -> file_descr ->
540 file_descr -> int
541 (** [create_process_env prog args env new_stdin new_stdout new_stderr]
542 works as {!Unix.create_process}, except that the extra argument
543 [env] specifies the environment passed to the program. *)
546 val open_process_in : string -> in_channel
547 (** High-level pipe and process management. This function
548 runs the given command in parallel with the program.
549 The standard output of the command is redirected to a pipe,
550 which can be read via the returned input channel.
551 The command is interpreted by the shell [/bin/sh] (cf. [system]). *)
553 val open_process_out : string -> out_channel
554 (** Same as {!Unix.open_process_in}, but redirect the standard input of
555 the command to a pipe. Data written to the returned output channel
556 is sent to the standard input of the command.
557 Warning: writes on output channels are buffered, hence be careful
558 to call {!Pervasives.flush} at the right times to ensure
559 correct synchronization. *)
561 val open_process : string -> in_channel * out_channel
562 (** Same as {!Unix.open_process_out}, but redirects both the standard input
563 and standard output of the command to pipes connected to the two
564 returned channels. The input channel is connected to the output
565 of the command, and the output channel to the input of the command. *)
567 val open_process_full :
568 string -> string array -> in_channel * out_channel * in_channel
569 (** Similar to {!Unix.open_process}, but the second argument specifies
570 the environment passed to the command. The result is a triple
571 of channels connected respectively to the standard output, standard input,
572 and standard error of the command. *)
574 val close_process_in : in_channel -> process_status
575 (** Close channels opened by {!Unix.open_process_in},
576 wait for the associated command to terminate,
577 and return its termination status. *)
579 val close_process_out : out_channel -> process_status
580 (** Close channels opened by {!Unix.open_process_out},
581 wait for the associated command to terminate,
582 and return its termination status. *)
584 val close_process : in_channel * out_channel -> process_status
585 (** Close channels opened by {!Unix.open_process},
586 wait for the associated command to terminate,
587 and return its termination status. *)
589 val close_process_full :
590 in_channel * out_channel * in_channel -> process_status
591 (** Close channels opened by {!Unix.open_process_full},
592 wait for the associated command to terminate,
593 and return its termination status. *)
596 (** {6 Symbolic links} *)
599 val symlink : string -> string -> unit
600 (** [symlink source dest] creates the file [dest] as a symbolic link
601 to the file [source]. *)
603 val readlink : string -> string
604 (** Read the contents of a link. *)
607 (** {6 Polling} *)
610 val select :
611 file_descr list -> file_descr list -> file_descr list -> float ->
612 file_descr list * file_descr list * file_descr list
613 (** Wait until some input/output operations become possible on
614 some channels. The three list arguments are, respectively, a set
615 of descriptors to check for reading (first argument), for writing
616 (second argument), or for exceptional conditions (third argument).
617 The fourth argument is the maximal timeout, in seconds; a
618 negative fourth argument means no timeout (unbounded wait).
619 The result is composed of three sets of descriptors: those ready
620 for reading (first component), ready for writing (second component),
621 and over which an exceptional condition is pending (third
622 component). *)
624 (** {6 Locking} *)
627 type lock_command =
628 F_ULOCK (** Unlock a region *)
629 | F_LOCK (** Lock a region for writing, and block if already locked *)
630 | F_TLOCK (** Lock a region for writing, or fail if already locked *)
631 | F_TEST (** Test a region for other process locks *)
632 | F_RLOCK (** Lock a region for reading, and block if already locked *)
633 | F_TRLOCK (** Lock a region for reading, or fail if already locked *)
634 (** Commands for {!Unix.lockf}. *)
636 val lockf : file_descr -> lock_command -> int -> unit
637 (** [lockf fd cmd size] puts a lock on a region of the file opened
638 as [fd]. The region starts at the current read/write position for
639 [fd] (as set by {!Unix.lseek}), and extends [size] bytes forward if
640 [size] is positive, [size] bytes backwards if [size] is negative,
641 or to the end of the file if [size] is zero.
642 A write lock prevents any other
643 process from acquiring a read or write lock on the region.
644 A read lock prevents any other
645 process from acquiring a write lock on the region, but lets
646 other processes acquire read locks on it.
648 The [F_LOCK] and [F_TLOCK] commands attempts to put a write lock
649 on the specified region.
650 The [F_RLOCK] and [F_TRLOCK] commands attempts to put a read lock
651 on the specified region.
652 If one or several locks put by another process prevent the current process
653 from acquiring the lock, [F_LOCK] and [F_RLOCK] block until these locks
654 are removed, while [F_TLOCK] and [F_TRLOCK] fail immediately with an
655 exception.
656 The [F_ULOCK] removes whatever locks the current process has on
657 the specified region.
658 Finally, the [F_TEST] command tests whether a write lock can be
659 acquired on the specified region, without actually putting a lock.
660 It returns immediately if successful, or fails otherwise. *)
663 (** {6 Signals}
664 Note: installation of signal handlers is performed via
665 the functions {!Sys.signal} and {!Sys.set_signal}.
668 val kill : int -> int -> unit
669 (** [kill pid sig] sends signal number [sig] to the process
670 with id [pid]. *)
672 type sigprocmask_command =
673 SIG_SETMASK
674 | SIG_BLOCK
675 | SIG_UNBLOCK
677 val sigprocmask : sigprocmask_command -> int list -> int list
678 (** [sigprocmask cmd sigs] changes the set of blocked signals.
679 If [cmd] is [SIG_SETMASK], blocked signals are set to those in
680 the list [sigs].
681 If [cmd] is [SIG_BLOCK], the signals in [sigs] are added to
682 the set of blocked signals.
683 If [cmd] is [SIG_UNBLOCK], the signals in [sigs] are removed
684 from the set of blocked signals.
685 [sigprocmask] returns the set of previously blocked signals. *)
687 val sigpending : unit -> int list
688 (** Return the set of blocked signals that are currently pending. *)
690 val sigsuspend : int list -> unit
691 (** [sigsuspend sigs] atomically sets the blocked signals to [sigs]
692 and waits for a non-ignored, non-blocked signal to be delivered.
693 On return, the blocked signals are reset to their initial value. *)
695 val pause : unit -> unit
696 (** Wait until a non-ignored, non-blocked signal is delivered. *)
699 (** {6 Time functions} *)
702 type process_times =
703 { tms_utime : float; (** User time for the process *)
704 tms_stime : float; (** System time for the process *)
705 tms_cutime : float; (** User time for the children processes *)
706 tms_cstime : float; (** System time for the children processes *)
708 (** The execution times (CPU times) of a process. *)
710 type tm =
711 { tm_sec : int; (** Seconds 0..60 *)
712 tm_min : int; (** Minutes 0..59 *)
713 tm_hour : int; (** Hours 0..23 *)
714 tm_mday : int; (** Day of month 1..31 *)
715 tm_mon : int; (** Month of year 0..11 *)
716 tm_year : int; (** Year - 1900 *)
717 tm_wday : int; (** Day of week (Sunday is 0) *)
718 tm_yday : int; (** Day of year 0..365 *)
719 tm_isdst : bool; (** Daylight time savings in effect *)
721 (** The type representing wallclock time and calendar date. *)
724 val time : unit -> float
725 (** Return the current time since 00:00:00 GMT, Jan. 1, 1970,
726 in seconds. *)
728 val gettimeofday : unit -> float
729 (** Same as {!Unix.time}, but with resolution better than 1 second. *)
731 val gmtime : float -> tm
732 (** Convert a time in seconds, as returned by {!Unix.time}, into a date and
733 a time. Assumes UTC (Coordinated Universal Time), also known as GMT. *)
735 val localtime : float -> tm
736 (** Convert a time in seconds, as returned by {!Unix.time}, into a date and
737 a time. Assumes the local time zone. *)
739 val mktime : tm -> float * tm
740 (** Convert a date and time, specified by the [tm] argument, into
741 a time in seconds, as returned by {!Unix.time}. The [tm_isdst],
742 [tm_wday] and [tm_yday] fields of [tm] are ignored. Also return a
743 normalized copy of the given [tm] record, with the [tm_wday],
744 [tm_yday], and [tm_isdst] fields recomputed from the other fields,
745 and the other fields normalized (so that, e.g., 40 October is
746 changed into 9 November). The [tm] argument is interpreted in the
747 local time zone. *)
749 val alarm : int -> int
750 (** Schedule a [SIGALRM] signal after the given number of seconds. *)
752 val sleep : int -> unit
753 (** Stop execution for the given number of seconds. *)
755 val times : unit -> process_times
756 (** Return the execution times of the process. *)
758 val utimes : string -> float -> float -> unit
759 (** Set the last access time (second arg) and last modification time
760 (third arg) for a file. Times are expressed in seconds from
761 00:00:00 GMT, Jan. 1, 1970. A time of [0.0] is interpreted as the
762 current time. *)
764 type interval_timer =
765 ITIMER_REAL
766 (** decrements in real time, and sends the signal [SIGALRM] when expired.*)
767 | ITIMER_VIRTUAL
768 (** decrements in process virtual time, and sends [SIGVTALRM] when expired. *)
769 | ITIMER_PROF
770 (** (for profiling) decrements both when the process
771 is running and when the system is running on behalf of the
772 process; it sends [SIGPROF] when expired. *)
773 (** The three kinds of interval timers. *)
775 type interval_timer_status =
776 { it_interval : float; (** Period *)
777 it_value : float; (** Current value of the timer *)
779 (** The type describing the status of an interval timer *)
781 val getitimer : interval_timer -> interval_timer_status
782 (** Return the current status of the given interval timer. *)
784 val setitimer :
785 interval_timer -> interval_timer_status -> interval_timer_status
786 (** [setitimer t s] sets the interval timer [t] and returns
787 its previous status. The [s] argument is interpreted as follows:
788 [s.it_value], if nonzero, is the time to the next timer expiration;
789 [s.it_interval], if nonzero, specifies a value to
790 be used in reloading it_value when the timer expires.
791 Setting [s.it_value] to zero disable the timer.
792 Setting [s.it_interval] to zero causes the timer to be disabled
793 after its next expiration. *)
796 (** {6 User id, group id} *)
799 val getuid : unit -> int
800 (** Return the user id of the user executing the process. *)
802 val geteuid : unit -> int
803 (** Return the effective user id under which the process runs. *)
805 val setuid : int -> unit
806 (** Set the real user id and effective user id for the process. *)
808 val getgid : unit -> int
809 (** Return the group id of the user executing the process. *)
811 val getegid : unit -> int
812 (** Return the effective group id under which the process runs. *)
814 val setgid : int -> unit
815 (** Set the real group id and effective group id for the process. *)
817 val getgroups : unit -> int array
818 (** Return the list of groups to which the user executing the process
819 belongs. *)
821 type passwd_entry =
822 { pw_name : string;
823 pw_passwd : string;
824 pw_uid : int;
825 pw_gid : int;
826 pw_gecos : string;
827 pw_dir : string;
828 pw_shell : string
830 (** Structure of entries in the [passwd] database. *)
832 type group_entry =
833 { gr_name : string;
834 gr_passwd : string;
835 gr_gid : int;
836 gr_mem : string array
838 (** Structure of entries in the [groups] database. *)
840 val getlogin : unit -> string
841 (** Return the login name of the user executing the process. *)
843 val getpwnam : string -> passwd_entry
844 (** Find an entry in [passwd] with the given name, or raise
845 [Not_found]. *)
847 val getgrnam : string -> group_entry
848 (** Find an entry in [group] with the given name, or raise
849 [Not_found]. *)
851 val getpwuid : int -> passwd_entry
852 (** Find an entry in [passwd] with the given user id, or raise
853 [Not_found]. *)
855 val getgrgid : int -> group_entry
856 (** Find an entry in [group] with the given group id, or raise
857 [Not_found]. *)
860 (** {6 Internet addresses} *)
863 type inet_addr
864 (** The abstract type of Internet addresses. *)
866 val inet_addr_of_string : string -> inet_addr
867 (** Conversion from the printable representation of an Internet
868 address to its internal representation. The argument string
869 consists of 4 numbers separated by periods ([XXX.YYY.ZZZ.TTT])
870 for IPv4 addresses, and up to 8 numbers separated by colons
871 for IPv6 addresses. Raise [Failure] when given a string that
872 does not match these formats. *)
874 val string_of_inet_addr : inet_addr -> string
875 (** Return the printable representation of the given Internet address.
876 See {!Unix.inet_addr_of_string} for a description of the
877 printable representation. *)
879 val inet_addr_any : inet_addr
880 (** A special IPv4 address, for use only with [bind], representing
881 all the Internet addresses that the host machine possesses. *)
883 val inet_addr_loopback : inet_addr
884 (** A special IPv4 address representing the host machine ([127.0.0.1]). *)
886 val inet6_addr_any : inet_addr
887 (** A special IPv6 address, for use only with [bind], representing
888 all the Internet addresses that the host machine possesses. *)
890 val inet6_addr_loopback : inet_addr
891 (** A special IPv6 address representing the host machine ([::1]). *)
894 (** {6 Sockets} *)
897 type socket_domain =
898 PF_UNIX (** Unix domain *)
899 | PF_INET (** Internet domain (IPv4) *)
900 | PF_INET6 (** Internet domain (IPv6) *)
901 (** The type of socket domains. *)
903 type socket_type =
904 SOCK_STREAM (** Stream socket *)
905 | SOCK_DGRAM (** Datagram socket *)
906 | SOCK_RAW (** Raw socket *)
907 | SOCK_SEQPACKET (** Sequenced packets socket *)
908 (** The type of socket kinds, specifying the semantics of
909 communications. *)
911 type sockaddr = ADDR_UNIX of string | ADDR_INET of inet_addr * int
912 (** The type of socket addresses. [ADDR_UNIX name] is a socket
913 address in the Unix domain; [name] is a file name in the file
914 system. [ADDR_INET(addr,port)] is a socket address in the Internet
915 domain; [addr] is the Internet address of the machine, and
916 [port] is the port number. *)
918 val socket : socket_domain -> socket_type -> int -> file_descr
919 (** Create a new socket in the given domain, and with the
920 given kind. The third argument is the protocol type; 0 selects
921 the default protocol for that kind of sockets. *)
923 val domain_of_sockaddr: sockaddr -> socket_domain
924 (** Return the socket domain adequate for the given socket address. *)
926 val socketpair :
927 socket_domain -> socket_type -> int -> file_descr * file_descr
928 (** Create a pair of unnamed sockets, connected together. *)
930 val accept : file_descr -> file_descr * sockaddr
931 (** Accept connections on the given socket. The returned descriptor
932 is a socket connected to the client; the returned address is
933 the address of the connecting client. *)
935 val bind : file_descr -> sockaddr -> unit
936 (** Bind a socket to an address. *)
938 val connect : file_descr -> sockaddr -> unit
939 (** Connect a socket to an address. *)
941 val listen : file_descr -> int -> unit
942 (** Set up a socket for receiving connection requests. The integer
943 argument is the maximal number of pending requests. *)
945 type shutdown_command =
946 SHUTDOWN_RECEIVE (** Close for receiving *)
947 | SHUTDOWN_SEND (** Close for sending *)
948 | SHUTDOWN_ALL (** Close both *)
949 (** The type of commands for [shutdown]. *)
952 val shutdown : file_descr -> shutdown_command -> unit
953 (** Shutdown a socket connection. [SHUTDOWN_SEND] as second argument
954 causes reads on the other end of the connection to return
955 an end-of-file condition.
956 [SHUTDOWN_RECEIVE] causes writes on the other end of the connection
957 to return a closed pipe condition ([SIGPIPE] signal). *)
959 val getsockname : file_descr -> sockaddr
960 (** Return the address of the given socket. *)
962 val getpeername : file_descr -> sockaddr
963 (** Return the address of the host connected to the given socket. *)
965 type msg_flag =
966 MSG_OOB
967 | MSG_DONTROUTE
968 | MSG_PEEK
969 (** The flags for {!Unix.recv}, {!Unix.recvfrom},
970 {!Unix.send} and {!Unix.sendto}. *)
972 val recv : file_descr -> string -> int -> int -> msg_flag list -> int
973 (** Receive data from a connected socket. *)
975 val recvfrom :
976 file_descr -> string -> int -> int -> msg_flag list -> int * sockaddr
977 (** Receive data from an unconnected socket. *)
979 val send : file_descr -> string -> int -> int -> msg_flag list -> int
980 (** Send data over a connected socket. *)
982 val sendto :
983 file_descr -> string -> int -> int -> msg_flag list -> sockaddr -> int
984 (** Send data over an unconnected socket. *)
988 (** {6 Socket options} *)
991 type socket_bool_option =
992 SO_DEBUG (** Record debugging information *)
993 | SO_BROADCAST (** Permit sending of broadcast messages *)
994 | SO_REUSEADDR (** Allow reuse of local addresses for bind *)
995 | SO_KEEPALIVE (** Keep connection active *)
996 | SO_DONTROUTE (** Bypass the standard routing algorithms *)
997 | SO_OOBINLINE (** Leave out-of-band data in line *)
998 | SO_ACCEPTCONN (** Report whether socket listening is enabled *)
999 (** The socket options that can be consulted with {!Unix.getsockopt}
1000 and modified with {!Unix.setsockopt}. These options have a boolean
1001 ([true]/[false]) value. *)
1003 type socket_int_option =
1004 SO_SNDBUF (** Size of send buffer *)
1005 | SO_RCVBUF (** Size of received buffer *)
1006 | SO_ERROR (** Report the error status and clear it *)
1007 | SO_TYPE (** Report the socket type *)
1008 | SO_RCVLOWAT (** Minimum number of bytes to process for input operations *)
1009 | SO_SNDLOWAT (** Minimum number of bytes to process for output operations *)
1010 (** The socket options that can be consulted with {!Unix.getsockopt_int}
1011 and modified with {!Unix.setsockopt_int}. These options have an
1012 integer value. *)
1014 type socket_optint_option =
1015 SO_LINGER (** Whether to linger on closed connections
1016 that have data present, and for how long
1017 (in seconds) *)
1018 (** The socket options that can be consulted with {!Unix.getsockopt_optint}
1019 and modified with {!Unix.setsockopt_optint}. These options have a
1020 value of type [int option], with [None] meaning ``disabled''. *)
1022 type socket_float_option =
1023 SO_RCVTIMEO (** Timeout for input operations *)
1024 | SO_SNDTIMEO (** Timeout for output operations *)
1025 (** The socket options that can be consulted with {!Unix.getsockopt_float}
1026 and modified with {!Unix.setsockopt_float}. These options have a
1027 floating-point value representing a time in seconds.
1028 The value 0 means infinite timeout. *)
1030 val getsockopt : file_descr -> socket_bool_option -> bool
1031 (** Return the current status of a boolean-valued option
1032 in the given socket. *)
1034 val setsockopt : file_descr -> socket_bool_option -> bool -> unit
1035 (** Set or clear a boolean-valued option in the given socket. *)
1037 external getsockopt_int :
1038 file_descr -> socket_int_option -> int = "unix_getsockopt_int"
1039 (** Same as {!Unix.getsockopt} for an integer-valued socket option. *)
1041 external setsockopt_int :
1042 file_descr -> socket_int_option -> int -> unit = "unix_setsockopt_int"
1043 (** Same as {!Unix.setsockopt} for an integer-valued socket option. *)
1045 external getsockopt_optint :
1046 file_descr -> socket_optint_option -> int option = "unix_getsockopt_optint"
1047 (** Same as {!Unix.getsockopt} for a socket option whose value is an [int option]. *)
1049 external setsockopt_optint :
1050 file_descr -> socket_optint_option -> int option ->
1051 unit = "unix_setsockopt_optint"
1052 (** Same as {!Unix.setsockopt} for a socket option whose value is an [int option]. *)
1054 external getsockopt_float :
1055 file_descr -> socket_float_option -> float = "unix_getsockopt_float"
1056 (** Same as {!Unix.getsockopt} for a socket option whose value is a floating-point number. *)
1058 external setsockopt_float :
1059 file_descr -> socket_float_option -> float -> unit = "unix_setsockopt_float"
1060 (** Same as {!Unix.setsockopt} for a socket option whose value is a floating-point number. *)
1062 (** {6 High-level network connection functions} *)
1065 val open_connection : sockaddr -> in_channel * out_channel
1066 (** Connect to a server at the given address.
1067 Return a pair of buffered channels connected to the server.
1068 Remember to call {!Pervasives.flush} on the output channel at the right
1069 times to ensure correct synchronization. *)
1071 val shutdown_connection : in_channel -> unit
1072 (** ``Shut down'' a connection established with {!Unix.open_connection};
1073 that is, transmit an end-of-file condition to the server reading
1074 on the other side of the connection. *)
1076 val establish_server : (in_channel -> out_channel -> unit) -> sockaddr -> unit
1077 (** Establish a server on the given address.
1078 The function given as first argument is called for each connection
1079 with two buffered channels connected to the client. A new process
1080 is created for each connection. The function {!Unix.establish_server}
1081 never returns normally. *)
1084 (** {6 Host and protocol databases} *)
1087 type host_entry =
1088 { h_name : string;
1089 h_aliases : string array;
1090 h_addrtype : socket_domain;
1091 h_addr_list : inet_addr array
1093 (** Structure of entries in the [hosts] database. *)
1095 type protocol_entry =
1096 { p_name : string;
1097 p_aliases : string array;
1098 p_proto : int
1100 (** Structure of entries in the [protocols] database. *)
1102 type service_entry =
1103 { s_name : string;
1104 s_aliases : string array;
1105 s_port : int;
1106 s_proto : string
1108 (** Structure of entries in the [services] database. *)
1110 val gethostname : unit -> string
1111 (** Return the name of the local host. *)
1113 val gethostbyname : string -> host_entry
1114 (** Find an entry in [hosts] with the given name, or raise
1115 [Not_found]. *)
1117 val gethostbyaddr : inet_addr -> host_entry
1118 (** Find an entry in [hosts] with the given address, or raise
1119 [Not_found]. *)
1121 val getprotobyname : string -> protocol_entry
1122 (** Find an entry in [protocols] with the given name, or raise
1123 [Not_found]. *)
1125 val getprotobynumber : int -> protocol_entry
1126 (** Find an entry in [protocols] with the given protocol number,
1127 or raise [Not_found]. *)
1129 val getservbyname : string -> string -> service_entry
1130 (** Find an entry in [services] with the given name, or raise
1131 [Not_found]. *)
1133 val getservbyport : int -> string -> service_entry
1134 (** Find an entry in [services] with the given service number,
1135 or raise [Not_found]. *)
1137 type addr_info =
1138 { ai_family : socket_domain; (** Socket domain *)
1139 ai_socktype : socket_type; (** Socket type *)
1140 ai_protocol : int; (** Socket protocol number *)
1141 ai_addr : sockaddr; (** Address *)
1142 ai_canonname : string (** Canonical host name *)
1144 (** Address information returned by {!Unix.getaddrinfo}. *)
1146 type getaddrinfo_option =
1147 AI_FAMILY of socket_domain (** Impose the given socket domain *)
1148 | AI_SOCKTYPE of socket_type (** Impose the given socket type *)
1149 | AI_PROTOCOL of int (** Impose the given protocol *)
1150 | AI_NUMERICHOST (** Do not call name resolver,
1151 expect numeric IP address *)
1152 | AI_CANONNAME (** Fill the [ai_canonname] field
1153 of the result *)
1154 | AI_PASSIVE (** Set address to ``any'' address
1155 for use with {!Unix.bind} *)
1156 (** Options to {!Unix.getaddrinfo}. *)
1158 val getaddrinfo:
1159 string -> string -> getaddrinfo_option list -> addr_info list
1160 (** [getaddrinfo host service opts] returns a list of {!Unix.addr_info}
1161 records describing socket parameters and addresses suitable for
1162 communicating with the given host and service. The empty list is
1163 returned if the host or service names are unknown, or the constraints
1164 expressed in [opts] cannot be satisfied.
1166 [host] is either a host name or the string representation of an IP
1167 address. [host] can be given as the empty string; in this case,
1168 the ``any'' address or the ``loopback'' address are used,
1169 depending whether [opts] contains [AI_PASSIVE].
1170 [service] is either a service name or the string representation of
1171 a port number. [service] can be given as the empty string;
1172 in this case, the port field of the returned addresses is set to 0.
1173 [opts] is a possibly empty list of options that allows the caller
1174 to force a particular socket domain (e.g. IPv6 only or IPv4 only)
1175 or a particular socket type (e.g. TCP only or UDP only). *)
1177 type name_info =
1178 { ni_hostname : string; (** Name or IP address of host *)
1179 ni_service : string } (** Name of service or port number *)
1180 (** Host and service information returned by {!Unix.getnameinfo}. *)
1182 type getnameinfo_option =
1183 NI_NOFQDN (** Do not qualify local host names *)
1184 | NI_NUMERICHOST (** Always return host as IP address *)
1185 | NI_NAMEREQD (** Fail if host name cannot be determined *)
1186 | NI_NUMERICSERV (** Always return service as port number *)
1187 | NI_DGRAM (** Consider the service as UDP-based
1188 instead of the default TCP *)
1189 (** Options to {!Unix.getnameinfo}. *)
1191 val getnameinfo : sockaddr -> getnameinfo_option list -> name_info
1192 (** [getnameinfo addr opts] returns the host name and service name
1193 corresponding to the socket address [addr]. [opts] is a possibly
1194 empty list of options that governs how these names are obtained.
1195 Raise [Not_found] if an error occurs. *)
1198 (** {6 Terminal interface} *)
1201 (** The following functions implement the POSIX standard terminal
1202 interface. They provide control over asynchronous communication ports
1203 and pseudo-terminals. Refer to the [termios] man page for a
1204 complete description. *)
1206 type terminal_io =
1208 (* input modes *)
1209 mutable c_ignbrk : bool; (** Ignore the break condition. *)
1210 mutable c_brkint : bool; (** Signal interrupt on break condition. *)
1211 mutable c_ignpar : bool; (** Ignore characters with parity errors. *)
1212 mutable c_parmrk : bool; (** Mark parity errors. *)
1213 mutable c_inpck : bool; (** Enable parity check on input. *)
1214 mutable c_istrip : bool; (** Strip 8th bit on input characters. *)
1215 mutable c_inlcr : bool; (** Map NL to CR on input. *)
1216 mutable c_igncr : bool; (** Ignore CR on input. *)
1217 mutable c_icrnl : bool; (** Map CR to NL on input. *)
1218 mutable c_ixon : bool; (** Recognize XON/XOFF characters on input. *)
1219 mutable c_ixoff : bool; (** Emit XON/XOFF chars to control input flow. *)
1220 (* Output modes: *)
1221 mutable c_opost : bool; (** Enable output processing. *)
1222 (* Control modes: *)
1223 mutable c_obaud : int; (** Output baud rate (0 means close connection).*)
1224 mutable c_ibaud : int; (** Input baud rate. *)
1225 mutable c_csize : int; (** Number of bits per character (5-8). *)
1226 mutable c_cstopb : int; (** Number of stop bits (1-2). *)
1227 mutable c_cread : bool; (** Reception is enabled. *)
1228 mutable c_parenb : bool; (** Enable parity generation and detection. *)
1229 mutable c_parodd : bool; (** Specify odd parity instead of even. *)
1230 mutable c_hupcl : bool; (** Hang up on last close. *)
1231 mutable c_clocal : bool; (** Ignore modem status lines. *)
1232 (* Local modes: *)
1233 mutable c_isig : bool; (** Generate signal on INTR, QUIT, SUSP. *)
1234 mutable c_icanon : bool; (** Enable canonical processing
1235 (line buffering and editing) *)
1236 mutable c_noflsh : bool; (** Disable flush after INTR, QUIT, SUSP. *)
1237 mutable c_echo : bool; (** Echo input characters. *)
1238 mutable c_echoe : bool; (** Echo ERASE (to erase previous character). *)
1239 mutable c_echok : bool; (** Echo KILL (to erase the current line). *)
1240 mutable c_echonl : bool; (** Echo NL even if c_echo is not set. *)
1241 (* Control characters: *)
1242 mutable c_vintr : char; (** Interrupt character (usually ctrl-C). *)
1243 mutable c_vquit : char; (** Quit character (usually ctrl-\). *)
1244 mutable c_verase : char; (** Erase character (usually DEL or ctrl-H). *)
1245 mutable c_vkill : char; (** Kill line character (usually ctrl-U). *)
1246 mutable c_veof : char; (** End-of-file character (usually ctrl-D). *)
1247 mutable c_veol : char; (** Alternate end-of-line char. (usually none). *)
1248 mutable c_vmin : int; (** Minimum number of characters to read
1249 before the read request is satisfied. *)
1250 mutable c_vtime : int; (** Maximum read wait (in 0.1s units). *)
1251 mutable c_vstart : char; (** Start character (usually ctrl-Q). *)
1252 mutable c_vstop : char; (** Stop character (usually ctrl-S). *)
1255 val tcgetattr : file_descr -> terminal_io
1256 (** Return the status of the terminal referred to by the given
1257 file descriptor. *)
1259 type setattr_when =
1260 TCSANOW
1261 | TCSADRAIN
1262 | TCSAFLUSH
1264 val tcsetattr : file_descr -> setattr_when -> terminal_io -> unit
1265 (** Set the status of the terminal referred to by the given
1266 file descriptor. The second argument indicates when the
1267 status change takes place: immediately ([TCSANOW]),
1268 when all pending output has been transmitted ([TCSADRAIN]),
1269 or after flushing all input that has been received but not
1270 read ([TCSAFLUSH]). [TCSADRAIN] is recommended when changing
1271 the output parameters; [TCSAFLUSH], when changing the input
1272 parameters. *)
1274 val tcsendbreak : file_descr -> int -> unit
1275 (** Send a break condition on the given file descriptor.
1276 The second argument is the duration of the break, in 0.1s units;
1277 0 means standard duration (0.25s). *)
1279 val tcdrain : file_descr -> unit
1280 (** Waits until all output written on the given file descriptor
1281 has been transmitted. *)
1283 type flush_queue =
1284 TCIFLUSH
1285 | TCOFLUSH
1286 | TCIOFLUSH
1288 val tcflush : file_descr -> flush_queue -> unit
1289 (** Discard data written on the given file descriptor but not yet
1290 transmitted, or data received but not yet read, depending on the
1291 second argument: [TCIFLUSH] flushes data received but not read,
1292 [TCOFLUSH] flushes data written but not transmitted, and
1293 [TCIOFLUSH] flushes both. *)
1295 type flow_action =
1296 TCOOFF
1297 | TCOON
1298 | TCIOFF
1299 | TCION
1301 val tcflow : file_descr -> flow_action -> unit
1302 (** Suspend or restart reception or transmission of data on
1303 the given file descriptor, depending on the second argument:
1304 [TCOOFF] suspends output, [TCOON] restarts output,
1305 [TCIOFF] transmits a STOP character to suspend input,
1306 and [TCION] transmits a START character to restart input. *)
1308 val setsid : unit -> int
1309 (** Put the calling process in a new session and detach it from
1310 its controlling terminal. *)