1Unix(3) OCaml library Unix(3)
2
3
4
6 Unix - Interface to the Unix system
7
9 Module Unix
10
12 Module Unix
13 : sig end
14
15
16 Interface to the Unix system
17
18
19
20
21
22
23
24
25 === Error report ===
26
27
28 type error =
29 | E2BIG (* Argument list too long *)
30 | EACCES (* Permission denied *)
31 | EAGAIN (* Resource temporarily unavailable; try again *)
32 | EBADF (* Bad file descriptor *)
33 | EBUSY (* Resource unavailable *)
34 | ECHILD (* No child process *)
35 | EDEADLK (* Resource deadlock would occur *)
36 | EDOM (* Domain error for math functions, etc. *)
37 | EEXIST (* File exists *)
38 | EFAULT (* Bad address *)
39 | EFBIG (* File too large *)
40 | EINTR (* Function interrupted by signal *)
41 | EINVAL (* Invalid argument *)
42 | EIO (* Hardware I/O error *)
43 | EISDIR (* Is a directory *)
44 | EMFILE (* Too many open files by the process *)
45 | EMLINK (* Too many links *)
46 | ENAMETOOLONG (* Filename too long *)
47 | ENFILE (* Too many open files in the system *)
48 | ENODEV (* No such device *)
49 | ENOENT (* No such file or directory *)
50 | ENOEXEC (* Not an executable file *)
51 | ENOLCK (* No locks available *)
52 | ENOMEM (* Not enough memory *)
53 | ENOSPC (* No space left on device *)
54 | ENOSYS (* Function not supported *)
55 | ENOTDIR (* Not a directory *)
56 | ENOTEMPTY (* Directory not empty *)
57 | ENOTTY (* Inappropriate I/O control operation *)
58 | ENXIO (* No such device or address *)
59 | EPERM (* Operation not permitted *)
60 | EPIPE (* Broken pipe *)
61 | ERANGE (* Result too large *)
62 | EROFS (* Read-only file system *)
63 | ESPIPE (* Invalid seek e.g. on a pipe *)
64 | ESRCH (* No such process *)
65 | EXDEV (* Invalid link *)
66 | EWOULDBLOCK (* Operation would block *)
67 | EINPROGRESS (* Operation now in progress *)
68 | EALREADY (* Operation already in progress *)
69 | ENOTSOCK (* Socket operation on non-socket *)
70 | EDESTADDRREQ (* Destination address required *)
71 | EMSGSIZE (* Message too long *)
72 | EPROTOTYPE (* Protocol wrong type for socket *)
73 | ENOPROTOOPT (* Protocol not available *)
74 | EPROTONOSUPPORT (* Protocol not supported *)
75 | ESOCKTNOSUPPORT (* Socket type not supported *)
76 | EOPNOTSUPP (* Operation not supported on socket *)
77 | EPFNOSUPPORT (* Protocol family not supported *)
78 | EAFNOSUPPORT (* Address family not supported by protocol family *)
79 | EADDRINUSE (* Address already in use *)
80 | EADDRNOTAVAIL (* Can't assign requested address *)
81 | ENETDOWN (* Network is down *)
82 | ENETUNREACH (* Network is unreachable *)
83 | ENETRESET (* Network dropped connection on reset *)
84 | ECONNABORTED (* Software caused connection abort *)
85 | ECONNRESET (* Connection reset by peer *)
86 | ENOBUFS (* No buffer space available *)
87 | EISCONN (* Socket is already connected *)
88 | ENOTCONN (* Socket is not connected *)
89 | ESHUTDOWN (* Can't send after socket shutdown *)
90 | ETOOMANYREFS (* Too many references: can't splice *)
91 | ETIMEDOUT (* Connection timed out *)
92 | ECONNREFUSED (* Connection refused *)
93 | EHOSTDOWN (* Host is down *)
94 | EHOSTUNREACH (* No route to host *)
95 | ELOOP (* Too many levels of symbolic links *)
96 | EOVERFLOW (* File size or position not representable *)
97 | EUNKNOWNERR of int (* Unknown error *)
98
99
100 The type of error codes. Errors defined in the POSIX standard and
101 additional errors from UNIX98 and BSD. All other errors are mapped to
102 EUNKNOWNERR.
103
104
105
106
107 exception Unix_error of error * string * string
108
109
110 Raised by the system calls below when an error is encountered. The
111 first component is the error code; the second component is the function
112 name; the third component is the string parameter to the function, if
113 it has one, or the empty string otherwise.
114
115
116
117
118 val error_message : error -> string
119
120 Return a string describing the given error code.
121
122
123
124
125 val handle_unix_error : ('a -> 'b) -> 'a -> 'b
126
127
128 handle_unix_error f x applies f to x and returns the result. If the
129 exception Unix_error is raised, it prints a message describing the
130 error and exits with code 2.
131
132
133
134
135
136 === Access to the process environment ===
137
138
139 val environment : unit -> string array
140
141 Return the process environment, as an array of strings with the format
142 ``variable=value''.
143
144
145
146
147 val getenv : string -> string
148
149 Return the value associated to a variable in the process environment.
150 Raise Not_found if the variable is unbound. (This function is identi‐
151 cal to Sys.getenv .)
152
153
154
155
156 val putenv : string -> string -> unit
157
158
159 Unix.putenv name value sets the value associated to a variable in the
160 process environment. name is the name of the environment variable, and
161 value its new associated value.
162
163
164
165
166
167 === Process handling ===
168
169
170 type process_status =
171 | WEXITED of int (* The process terminated normally by exit ; the
172 argument is the return code. *)
173 | WSIGNALED of int (* The process was killed by a signal; the argu‐
174 ment is the signal number. *)
175 | WSTOPPED of int (* The process was stopped by a signal; the argu‐
176 ment is the signal number. *)
177
178
179 The termination status of a process. See module Sys for the defini‐
180 tions of the standard signal numbers. Note that they are not the num‐
181 bers used by the OS.
182
183
184
185 type wait_flag =
186 | WNOHANG (* do not block if no child has died yet, but immediately
187 return with a pid equal to 0. *)
188 | WUNTRACED (* report also the children that receive stop signals. *)
189
190
191 Flags for Unix.waitpid .
192
193
194
195
196 val execv : string -> string array -> 'a
197
198
199 execv prog args execute the program in file prog , with the arguments
200 args , and the current process environment. These execv* functions
201 never return: on success, the current program is replaced by the new
202 one; on failure, a Unix.Unix_error exception is raised.
203
204
205
206
207 val execve : string -> string array -> string array -> 'a
208
209 Same as Unix.execv , except that the third argument provides the envi‐
210 ronment to the program executed.
211
212
213
214
215 val execvp : string -> string array -> 'a
216
217 Same as Unix.execv , except that the program is searched in the path.
218
219
220
221
222 val execvpe : string -> string array -> string array -> 'a
223
224 Same as Unix.execve , except that the program is searched in the path.
225
226
227
228
229 val fork : unit -> int
230
231 Fork a new process. The returned integer is 0 for the child process,
232 the pid of the child process for the parent process.
233
234
235
236
237 val wait : unit -> int * process_status
238
239 Wait until one of the children processes die, and return its pid and
240 termination status.
241
242
243
244
245 val waitpid : wait_flag list -> int -> int * process_status
246
247 Same as Unix.wait , but waits for the child process whose pid is given.
248 A pid of -1 means wait for any child. A pid of 0 means wait for any
249 child in the same process group as the current process. Negative pid
250 arguments represent process groups. The list of options indicates
251 whether waitpid should return immediately without waiting, or also
252 report stopped children.
253
254
255
256
257 val system : string -> process_status
258
259 Execute the given command, wait until it terminates, and return its
260 termination status. The string is interpreted by the shell /bin/sh and
261 therefore can contain redirections, quotes, variables, etc. The result
262 WEXITED 127 indicates that the shell couldn't be executed.
263
264
265
266
267 val getpid : unit -> int
268
269 Return the pid of the process.
270
271
272
273
274 val getppid : unit -> int
275
276 Return the pid of the parent process.
277
278
279
280
281 val nice : int -> int
282
283 Change the process priority. The integer argument is added to the
284 ``nice'' value. (Higher values of the ``nice'' value mean lower priori‐
285 ties.) Return the new nice value.
286
287
288
289
290
291 === Basic file input/output ===
292
293
294 type file_descr
295
296
297 The abstract type of file descriptors.
298
299
300
301
302 val stdin : file_descr
303
304 File descriptor for standard input.
305
306
307
308
309 val stdout : file_descr
310
311 File descriptor for standard output.
312
313
314
315
316 val stderr : file_descr
317
318 File descriptor for standard error.
319
320
321
322 type open_flag =
323 | O_RDONLY (* Open for reading *)
324 | O_WRONLY (* Open for writing *)
325 | O_RDWR (* Open for reading and writing *)
326 | O_NONBLOCK (* Open in non-blocking mode *)
327 | O_APPEND (* Open for append *)
328 | O_CREAT (* Create if nonexistent *)
329 | O_TRUNC (* Truncate to 0 length if existing *)
330 | O_EXCL (* Fail if existing *)
331 | O_NOCTTY (* Don't make this dev a controlling tty *)
332 | O_DSYNC (* Writes complete as `Synchronised I/O data integrity com‐
333 pletion' *)
334 | O_SYNC (* Writes complete as `Synchronised I/O file integrity com‐
335 pletion' *)
336 | O_RSYNC (* Reads complete as writes (depending on O_SYNC/O_DSYNC)
337 *)
338
339
340 The flags to Unix.openfile .
341
342
343
344 type file_perm = int
345
346
347 The type of file access rights, e.g. 0o640 is read and write for user,
348 read for group, none for others
349
350
351
352
353 val openfile : string -> open_flag list -> file_perm -> file_descr
354
355 Open the named file with the given flags. Third argument is the permis‐
356 sions to give to the file if it is created. Return a file descriptor on
357 the named file.
358
359
360
361
362 val close : file_descr -> unit
363
364 Close a file descriptor.
365
366
367
368
369 val read : file_descr -> string -> int -> int -> int
370
371
372 read fd buff ofs len reads len characters from descriptor fd , storing
373 them in string buff , starting at position ofs in string buff . Return
374 the number of characters actually read.
375
376
377
378
379 val write : file_descr -> string -> int -> int -> int
380
381
382 write fd buff ofs len writes len characters to descriptor fd , taking
383 them from string buff , starting at position ofs in string buff .
384 Return the number of characters actually written. write repeats the
385 writing operation until all characters have been written or an error
386 occurs.
387
388
389
390
391 val single_write : file_descr -> string -> int -> int -> int
392
393 Same as write , but attempts to write only once. Thus, if an error
394 occurs, single_write guarantees that no data has been written.
395
396
397
398
399
400 === Interfacing with the standard input/output library ===
401
402
403 val in_channel_of_descr : file_descr -> Pervasives.in_channel
404
405 Create an input channel reading from the given descriptor. The channel
406 is initially in binary mode; use set_binary_mode_in ic false if text
407 mode is desired.
408
409
410
411
412 val out_channel_of_descr : file_descr -> Pervasives.out_channel
413
414 Create an output channel writing on the given descriptor. The channel
415 is initially in binary mode; use set_binary_mode_out oc false if text
416 mode is desired.
417
418
419
420
421 val descr_of_in_channel : Pervasives.in_channel -> file_descr
422
423 Return the descriptor corresponding to an input channel.
424
425
426
427
428 val descr_of_out_channel : Pervasives.out_channel -> file_descr
429
430 Return the descriptor corresponding to an output channel.
431
432
433
434
435
436 === Seeking and truncating ===
437
438
439 type seek_command =
440 | SEEK_SET (* indicates positions relative to the beginning of the
441 file *)
442 | SEEK_CUR (* indicates positions relative to the current position *)
443 | SEEK_END (* indicates positions relative to the end of the file *)
444
445
446 Positioning modes for Unix.lseek .
447
448
449
450
451 val lseek : file_descr -> int -> seek_command -> int
452
453 Set the current position for a file descriptor
454
455
456
457
458 val truncate : string -> int -> unit
459
460 Truncates the named file to the given size.
461
462
463
464
465 val ftruncate : file_descr -> int -> unit
466
467 Truncates the file corresponding to the given descriptor to the given
468 size.
469
470
471
472
473
474 === File status ===
475
476
477 type file_kind =
478 | S_REG (* Regular file *)
479 | S_DIR (* Directory *)
480 | S_CHR (* Character device *)
481 | S_BLK (* Block device *)
482 | S_LNK (* Symbolic link *)
483 | S_FIFO (* Named pipe *)
484 | S_SOCK (* Socket *)
485
486
487
488
489 type stats = {
490 st_dev : int ; (* Device number *)
491 st_ino : int ; (* Inode number *)
492 st_kind : file_kind ; (* Kind of the file *)
493 st_perm : file_perm ; (* Access rights *)
494 st_nlink : int ; (* Number of links *)
495 st_uid : int ; (* User id of the owner *)
496 st_gid : int ; (* Group ID of the file's group *)
497 st_rdev : int ; (* Device minor number *)
498 st_size : int ; (* Size in bytes *)
499 st_atime : float ; (* Last access time *)
500 st_mtime : float ; (* Last modification time *)
501 st_ctime : float ; (* Last status change time *)
502 }
503
504
505 The informations returned by the Unix.stat calls.
506
507
508
509
510 val stat : string -> stats
511
512 Return the information for the named file.
513
514
515
516
517 val lstat : string -> stats
518
519 Same as Unix.stat , but in case the file is a symbolic link, return the
520 information for the link itself.
521
522
523
524
525 val fstat : file_descr -> stats
526
527 Return the information for the file associated with the given descrip‐
528 tor.
529
530
531
532
533 val isatty : file_descr -> bool
534
535 Return true if the given file descriptor refers to a terminal or con‐
536 sole window, false otherwise.
537
538
539
540
541
542 === File operations on large files ===
543
544
545 module LargeFile : sig end
546
547
548 File operations on large files. This sub-module provides 64-bit vari‐
549 ants of the functions Unix.lseek (for positioning a file descriptor),
550 Unix.truncate and Unix.ftruncate (for changing the size of a file), and
551 Unix.stat , Unix.lstat and Unix.fstat (for obtaining information on
552 files). These alternate functions represent positions and sizes by
553 64-bit integers (type int64 ) instead of regular integers (type int ),
554 thus allowing operating on files whose sizes are greater than max_int .
555
556
557
558
559
560 === Operations on file names ===
561
562
563 val unlink : string -> unit
564
565 Removes the named file
566
567
568
569
570 val rename : string -> string -> unit
571
572
573 rename old new changes the name of a file from old to new .
574
575
576
577
578 val link : string -> string -> unit
579
580
581 link source dest creates a hard link named dest to the file named
582 source .
583
584
585
586
587
588 === File permissions and ownership ===
589
590
591 type access_permission =
592 | R_OK (* Read permission *)
593 | W_OK (* Write permission *)
594 | X_OK (* Execution permission *)
595 | F_OK (* File exists *)
596
597
598 Flags for the Unix.access call.
599
600
601
602
603 val chmod : string -> file_perm -> unit
604
605 Change the permissions of the named file.
606
607
608
609
610 val fchmod : file_descr -> file_perm -> unit
611
612 Change the permissions of an opened file.
613
614
615
616
617 val chown : string -> int -> int -> unit
618
619 Change the owner uid and owner gid of the named file.
620
621
622
623
624 val fchown : file_descr -> int -> int -> unit
625
626 Change the owner uid and owner gid of an opened file.
627
628
629
630
631 val umask : int -> int
632
633 Set the process's file mode creation mask, and return the previous
634 mask.
635
636
637
638
639 val access : string -> access_permission list -> unit
640
641 Check that the process has the given permissions over the named file.
642 Raise Unix_error otherwise.
643
644
645
646
647
648 === Operations on file descriptors ===
649
650
651 val dup : file_descr -> file_descr
652
653 Return a new file descriptor referencing the same file as the given
654 descriptor.
655
656
657
658
659 val dup2 : file_descr -> file_descr -> unit
660
661
662 dup2 fd1 fd2 duplicates fd1 to fd2 , closing fd2 if already opened.
663
664
665
666
667 val set_nonblock : file_descr -> unit
668
669 Set the ``non-blocking'' flag on the given descriptor. When the
670 non-blocking flag is set, reading on a descriptor on which there is
671 temporarily no data available raises the EAGAIN or EWOULDBLOCK error
672 instead of blocking; writing on a descriptor on which there is tempo‐
673 rarily no room for writing also raises EAGAIN or EWOULDBLOCK .
674
675
676
677
678 val clear_nonblock : file_descr -> unit
679
680 Clear the ``non-blocking'' flag on the given descriptor. See
681 Unix.set_nonblock .
682
683
684
685
686 val set_close_on_exec : file_descr -> unit
687
688 Set the ``close-on-exec'' flag on the given descriptor. A descriptor
689 with the close-on-exec flag is automatically closed when the current
690 process starts another program with one of the exec functions.
691
692
693
694
695 val clear_close_on_exec : file_descr -> unit
696
697 Clear the ``close-on-exec'' flag on the given descriptor. See
698 Unix.set_close_on_exec .
699
700
701
702
703
704 === Directories ===
705
706
707 val mkdir : string -> file_perm -> unit
708
709 Create a directory with the given permissions.
710
711
712
713
714 val rmdir : string -> unit
715
716 Remove an empty directory.
717
718
719
720
721 val chdir : string -> unit
722
723 Change the process working directory.
724
725
726
727
728 val getcwd : unit -> string
729
730 Return the name of the current working directory.
731
732
733
734
735 val chroot : string -> unit
736
737 Change the process root directory.
738
739
740
741 type dir_handle
742
743
744 The type of descriptors over opened directories.
745
746
747
748
749 val opendir : string -> dir_handle
750
751 Open a descriptor on a directory
752
753
754
755
756 val readdir : dir_handle -> string
757
758 Return the next entry in a directory.
759
760 Raises End_of_file when the end of the directory has been reached.
761
762
763
764
765 val rewinddir : dir_handle -> unit
766
767 Reposition the descriptor to the beginning of the directory
768
769
770
771
772 val closedir : dir_handle -> unit
773
774 Close a directory descriptor.
775
776
777
778
779
780 === Pipes and redirections ===
781
782
783 val pipe : unit -> file_descr * file_descr
784
785 Create a pipe. The first component of the result is opened for reading,
786 that's the exit to the pipe. The second component is opened for writ‐
787 ing, that's the entrance to the pipe.
788
789
790
791
792 val mkfifo : string -> file_perm -> unit
793
794 Create a named pipe with the given permissions.
795
796
797
798
799
800 === High-level process and redirection management ===
801
802
803 val create_process : string -> string array -> file_descr -> file_descr
804 -> file_descr -> int
805
806
807 create_process prog args new_stdin new_stdout new_stderr forks a new
808 process that executes the program in file prog , with arguments args .
809 The pid of the new process is returned immediately; the new process
810 executes concurrently with the current process. The standard input and
811 outputs of the new process are connected to the descriptors new_stdin ,
812 new_stdout and new_stderr . Passing e.g. stdout for new_stdout pre‐
813 vents the redirection and causes the new process to have the same stan‐
814 dard output as the current process. The executable file prog is
815 searched in the path. The new process has the same environment as the
816 current process.
817
818
819
820
821 val create_process_env : string -> string array -> string array ->
822 file_descr -> file_descr -> file_descr -> int
823
824
825 create_process_env prog args env new_stdin new_stdout new_stderr works
826 as Unix.create_process , except that the extra argument env specifies
827 the environment passed to the program.
828
829
830
831
832 val open_process_in : string -> Pervasives.in_channel
833
834 High-level pipe and process management. This function runs the given
835 command in parallel with the program. The standard output of the com‐
836 mand is redirected to a pipe, which can be read via the returned input
837 channel. The command is interpreted by the shell /bin/sh (cf. system
838 ).
839
840
841
842
843 val open_process_out : string -> Pervasives.out_channel
844
845 Same as Unix.open_process_in , but redirect the standard input of the
846 command to a pipe. Data written to the returned output channel is sent
847 to the standard input of the command. Warning: writes on output chan‐
848 nels are buffered, hence be careful to call Pervasives.flush at the
849 right times to ensure correct synchronization.
850
851
852
853
854 val open_process : string -> Pervasives.in_channel * Perva‐
855 sives.out_channel
856
857 Same as Unix.open_process_out , but redirects both the standard input
858 and standard output of the command to pipes connected to the two
859 returned channels. The input channel is connected to the output of the
860 command, and the output channel to the input of the command.
861
862
863
864
865 val open_process_full : string -> string array -> Pervasives.in_channel
866 * Pervasives.out_channel * Pervasives.in_channel
867
868 Similar to Unix.open_process , but the second argument specifies the
869 environment passed to the command. The result is a triple of channels
870 connected respectively to the standard output, standard input, and
871 standard error of the command.
872
873
874
875
876 val close_process_in : Pervasives.in_channel -> process_status
877
878 Close channels opened by Unix.open_process_in , wait for the associated
879 command to terminate, and return its termination status.
880
881
882
883
884 val close_process_out : Pervasives.out_channel -> process_status
885
886 Close channels opened by Unix.open_process_out , wait for the associ‐
887 ated command to terminate, and return its termination status.
888
889
890
891
892 val close_process : Pervasives.in_channel * Pervasives.out_channel ->
893 process_status
894
895 Close channels opened by Unix.open_process , wait for the associated
896 command to terminate, and return its termination status.
897
898
899
900
901 val close_process_full : Pervasives.in_channel * Pervasives.out_channel
902 * Pervasives.in_channel -> process_status
903
904 Close channels opened by Unix.open_process_full , wait for the associ‐
905 ated command to terminate, and return its termination status.
906
907
908
909
910
911 === Symbolic links ===
912
913
914 val symlink : string -> string -> unit
915
916
917 symlink source dest creates the file dest as a symbolic link to the
918 file source .
919
920
921
922
923 val readlink : string -> string
924
925 Read the contents of a link.
926
927
928
929
930
931 === Polling ===
932
933
934 val select : file_descr list -> file_descr list -> file_descr list ->
935 float -> file_descr list * file_descr list * file_descr list
936
937 Wait until some input/output operations become possible on some chan‐
938 nels. The three list arguments are, respectively, a set of descriptors
939 to check for reading (first argument), for writing (second argument),
940 or for exceptional conditions (third argument). The fourth argument is
941 the maximal timeout, in seconds; a negative fourth argument means no
942 timeout (unbounded wait). The result is composed of three sets of
943 descriptors: those ready for reading (first component), ready for writ‐
944 ing (second component), and over which an exceptional condition is
945 pending (third component).
946
947
948
949
950
951 === Locking ===
952
953
954 type lock_command =
955 | F_ULOCK (* Unlock a region *)
956 | F_LOCK (* Lock a region for writing, and block if already locked *)
957 | F_TLOCK (* Lock a region for writing, or fail if already locked *)
958 | F_TEST (* Test a region for other process locks *)
959 | F_RLOCK (* Lock a region for reading, and block if already locked
960 *)
961 | F_TRLOCK (* Lock a region for reading, or fail if already locked *)
962
963
964 Commands for Unix.lockf .
965
966
967
968
969 val lockf : file_descr -> lock_command -> int -> unit
970
971
972 lockf fd cmd size puts a lock on a region of the file opened as fd .
973 The region starts at the current read/write position for fd (as set by
974 Unix.lseek ), and extends size bytes forward if size is positive, size
975 bytes backwards if size is negative, or to the end of the file if size
976 is zero. A write lock prevents any other process from acquiring a read
977 or write lock on the region. A read lock prevents any other process
978 from acquiring a write lock on the region, but lets other processes
979 acquire read locks on it.
980
981 The F_LOCK and F_TLOCK commands attempts to put a write lock on the
982 specified region. The F_RLOCK and F_TRLOCK commands attempts to put a
983 read lock on the specified region. If one or several locks put by
984 another process prevent the current process from acquiring the lock,
985 F_LOCK and F_RLOCK block until these locks are removed, while F_TLOCK
986 and F_TRLOCK fail immediately with an exception. The F_ULOCK removes
987 whatever locks the current process has on the specified region.
988 Finally, the F_TEST command tests whether a write lock can be acquired
989 on the specified region, without actually putting a lock. It returns
990 immediately if successful, or fails otherwise.
991
992
993
994
995
996 === Signals Note: installation of signal handlers is performed via the
997 functions Sys.signal and Sys.set_signal. ===
998
999
1000 val kill : int -> int -> unit
1001
1002
1003 kill pid sig sends signal number sig to the process with id pid .
1004
1005
1006
1007 type sigprocmask_command =
1008 | SIG_SETMASK
1009 | SIG_BLOCK
1010 | SIG_UNBLOCK
1011
1012
1013
1014
1015
1016 val sigprocmask : sigprocmask_command -> int list -> int list
1017
1018
1019 sigprocmask cmd sigs changes the set of blocked signals. If cmd is
1020 SIG_SETMASK , blocked signals are set to those in the list sigs . If
1021 cmd is SIG_BLOCK , the signals in sigs are added to the set of blocked
1022 signals. If cmd is SIG_UNBLOCK , the signals in sigs are removed from
1023 the set of blocked signals. sigprocmask returns the set of previously
1024 blocked signals.
1025
1026
1027
1028
1029 val sigpending : unit -> int list
1030
1031 Return the set of blocked signals that are currently pending.
1032
1033
1034
1035
1036 val sigsuspend : int list -> unit
1037
1038
1039 sigsuspend sigs atomically sets the blocked signals to sigs and waits
1040 for a non-ignored, non-blocked signal to be delivered. On return, the
1041 blocked signals are reset to their initial value.
1042
1043
1044
1045
1046 val pause : unit -> unit
1047
1048 Wait until a non-ignored, non-blocked signal is delivered.
1049
1050
1051
1052
1053
1054 === Time functions ===
1055
1056
1057 type process_times = {
1058 tms_utime : float ; (* User time for the process *)
1059 tms_stime : float ; (* System time for the process *)
1060 tms_cutime : float ; (* User time for the children processes *)
1061 tms_cstime : float ; (* System time for the children processes *)
1062 }
1063
1064
1065 The execution times (CPU times) of a process.
1066
1067
1068
1069 type tm = {
1070 tm_sec : int ; (* Seconds 0..60 *)
1071 tm_min : int ; (* Minutes 0..59 *)
1072 tm_hour : int ; (* Hours 0..23 *)
1073 tm_mday : int ; (* Day of month 1..31 *)
1074 tm_mon : int ; (* Month of year 0..11 *)
1075 tm_year : int ; (* Year - 1900 *)
1076 tm_wday : int ; (* Day of week (Sunday is 0) *)
1077 tm_yday : int ; (* Day of year 0..365 *)
1078 tm_isdst : bool ; (* Daylight time savings in effect *)
1079 }
1080
1081
1082 The type representing wallclock time and calendar date.
1083
1084
1085
1086
1087 val time : unit -> float
1088
1089 Return the current time since 00:00:00 GMT, Jan. 1, 1970, in seconds.
1090
1091
1092
1093
1094 val gettimeofday : unit -> float
1095
1096 Same as Unix.time , but with resolution better than 1 second.
1097
1098
1099
1100
1101 val gmtime : float -> tm
1102
1103 Convert a time in seconds, as returned by Unix.time , into a date and a
1104 time. Assumes UTC (Coordinated Universal Time), also known as GMT.
1105
1106
1107
1108
1109 val localtime : float -> tm
1110
1111 Convert a time in seconds, as returned by Unix.time , into a date and a
1112 time. Assumes the local time zone.
1113
1114
1115
1116
1117 val mktime : tm -> float * tm
1118
1119 Convert a date and time, specified by the tm argument, into a time in
1120 seconds, as returned by Unix.time . The tm_isdst , tm_wday and tm_yday
1121 fields of tm are ignored. Also return a normalized copy of the given
1122 tm record, with the tm_wday , tm_yday , and tm_isdst fields recomputed
1123 from the other fields, and the other fields normalized (so that, e.g.,
1124 40 October is changed into 9 November). The tm argument is interpreted
1125 in the local time zone.
1126
1127
1128
1129
1130 val alarm : int -> int
1131
1132 Schedule a SIGALRM signal after the given number of seconds.
1133
1134
1135
1136
1137 val sleep : int -> unit
1138
1139 Stop execution for the given number of seconds.
1140
1141
1142
1143
1144 val times : unit -> process_times
1145
1146 Return the execution times of the process.
1147
1148
1149
1150
1151 val utimes : string -> float -> float -> unit
1152
1153 Set the last access time (second arg) and last modification time (third
1154 arg) for a file. Times are expressed in seconds from 00:00:00 GMT, Jan.
1155 1, 1970. A time of 0.0 is interpreted as the current time.
1156
1157
1158
1159 type interval_timer =
1160 | ITIMER_REAL (* decrements in real time, and sends the signal
1161 SIGALRM when expired. *)
1162 | ITIMER_VIRTUAL (* decrements in process virtual time, and sends
1163 SIGVTALRM when expired. *)
1164 | ITIMER_PROF (* (for profiling) decrements both when the process is
1165 running and when the system is running on behalf of the process; it
1166 sends SIGPROF when expired. *)
1167
1168
1169 The three kinds of interval timers.
1170
1171
1172
1173 type interval_timer_status = {
1174 it_interval : float ; (* Period *)
1175 it_value : float ; (* Current value of the timer *)
1176 }
1177
1178
1179 The type describing the status of an interval timer
1180
1181
1182
1183
1184 val getitimer : interval_timer -> interval_timer_status
1185
1186 Return the current status of the given interval timer.
1187
1188
1189
1190
1191 val setitimer : interval_timer -> interval_timer_status -> inter‐
1192 val_timer_status
1193
1194
1195 setitimer t s sets the interval timer t and returns its previous sta‐
1196 tus. The s argument is interpreted as follows: s.it_value , if nonzero,
1197 is the time to the next timer expiration; s.it_interval , if nonzero,
1198 specifies a value to be used in reloading it_value when the timer
1199 expires. Setting s.it_value to zero disable the timer. Setting
1200 s.it_interval to zero causes the timer to be disabled after its next
1201 expiration.
1202
1203
1204
1205
1206
1207 === User id, group id ===
1208
1209
1210 val getuid : unit -> int
1211
1212 Return the user id of the user executing the process.
1213
1214
1215
1216
1217 val geteuid : unit -> int
1218
1219 Return the effective user id under which the process runs.
1220
1221
1222
1223
1224 val setuid : int -> unit
1225
1226 Set the real user id and effective user id for the process.
1227
1228
1229
1230
1231 val getgid : unit -> int
1232
1233 Return the group id of the user executing the process.
1234
1235
1236
1237
1238 val getegid : unit -> int
1239
1240 Return the effective group id under which the process runs.
1241
1242
1243
1244
1245 val setgid : int -> unit
1246
1247 Set the real group id and effective group id for the process.
1248
1249
1250
1251
1252 val getgroups : unit -> int array
1253
1254 Return the list of groups to which the user executing the process
1255 belongs.
1256
1257
1258
1259 type passwd_entry = {
1260 pw_name : string ;
1261 pw_passwd : string ;
1262 pw_uid : int ;
1263 pw_gid : int ;
1264 pw_gecos : string ;
1265 pw_dir : string ;
1266 pw_shell : string ;
1267 }
1268
1269
1270 Structure of entries in the passwd database.
1271
1272
1273
1274 type group_entry = {
1275 gr_name : string ;
1276 gr_passwd : string ;
1277 gr_gid : int ;
1278 gr_mem : string array ;
1279 }
1280
1281
1282 Structure of entries in the groups database.
1283
1284
1285
1286
1287 val getlogin : unit -> string
1288
1289 Return the login name of the user executing the process.
1290
1291
1292
1293
1294 val getpwnam : string -> passwd_entry
1295
1296 Find an entry in passwd with the given name, or raise Not_found .
1297
1298
1299
1300
1301 val getgrnam : string -> group_entry
1302
1303 Find an entry in group with the given name, or raise Not_found .
1304
1305
1306
1307
1308 val getpwuid : int -> passwd_entry
1309
1310 Find an entry in passwd with the given user id, or raise Not_found .
1311
1312
1313
1314
1315 val getgrgid : int -> group_entry
1316
1317 Find an entry in group with the given group id, or raise Not_found .
1318
1319
1320
1321
1322
1323 === Internet addresses ===
1324
1325
1326 type inet_addr
1327
1328
1329 The abstract type of Internet addresses.
1330
1331
1332
1333
1334 val inet_addr_of_string : string -> inet_addr
1335
1336 Conversion from the printable representation of an Internet address to
1337 its internal representation. The argument string consists of 4 numbers
1338 separated by periods ( XXX.YYY.ZZZ.TTT ) for IPv4 addresses, and up to
1339 8 numbers separated by colons for IPv6 addresses. Raise Failure when
1340 given a string that does not match these formats.
1341
1342
1343
1344
1345 val string_of_inet_addr : inet_addr -> string
1346
1347 Return the printable representation of the given Internet address. See
1348 Unix.inet_addr_of_string for a description of the printable representa‐
1349 tion.
1350
1351
1352
1353
1354 val inet_addr_any : inet_addr
1355
1356 A special IPv4 address, for use only with bind , representing all the
1357 Internet addresses that the host machine possesses.
1358
1359
1360
1361
1362 val inet_addr_loopback : inet_addr
1363
1364 A special IPv4 address representing the host machine ( 127.0.0.1 ).
1365
1366
1367
1368
1369 val inet6_addr_any : inet_addr
1370
1371 A special IPv6 address, for use only with bind , representing all the
1372 Internet addresses that the host machine possesses.
1373
1374
1375
1376
1377 val inet6_addr_loopback : inet_addr
1378
1379 A special IPv6 address representing the host machine ( ::1 ).
1380
1381
1382
1383
1384
1385 === Sockets ===
1386
1387
1388 type socket_domain =
1389 | PF_UNIX (* Unix domain *)
1390 | PF_INET (* Internet domain (IPv4) *)
1391 | PF_INET6 (* Internet domain (IPv6) *)
1392
1393
1394 The type of socket domains. Not all platforms support IPv6 sockets
1395 (type PF_INET6 ).
1396
1397
1398
1399 type socket_type =
1400 | SOCK_STREAM (* Stream socket *)
1401 | SOCK_DGRAM (* Datagram socket *)
1402 | SOCK_RAW (* Raw socket *)
1403 | SOCK_SEQPACKET (* Sequenced packets socket *)
1404
1405
1406 The type of socket kinds, specifying the semantics of communications.
1407
1408
1409
1410 type sockaddr =
1411 | ADDR_UNIX of string
1412 | ADDR_INET of inet_addr * int (* The type of socket addresses.
1413 ADDR_UNIX name is a socket address in the Unix domain; name is a file
1414 name in the file system. ADDR_INET(addr,port) is a socket address in
1415 the Internet domain; addr is the Internet address of the machine, and
1416 port is the port number. *)
1417
1418
1419
1420
1421
1422 val socket : socket_domain -> socket_type -> int -> file_descr
1423
1424 Create a new socket in the given domain, and with the given kind. The
1425 third argument is the protocol type; 0 selects the default protocol for
1426 that kind of sockets.
1427
1428
1429
1430
1431 val domain_of_sockaddr : sockaddr -> socket_domain
1432
1433 Return the socket domain adequate for the given socket address.
1434
1435
1436
1437
1438 val socketpair : socket_domain -> socket_type -> int -> file_descr *
1439 file_descr
1440
1441 Create a pair of unnamed sockets, connected together.
1442
1443
1444
1445
1446 val accept : file_descr -> file_descr * sockaddr
1447
1448 Accept connections on the given socket. The returned descriptor is a
1449 socket connected to the client; the returned address is the address of
1450 the connecting client.
1451
1452
1453
1454
1455 val bind : file_descr -> sockaddr -> unit
1456
1457 Bind a socket to an address.
1458
1459
1460
1461
1462 val connect : file_descr -> sockaddr -> unit
1463
1464 Connect a socket to an address.
1465
1466
1467
1468
1469 val listen : file_descr -> int -> unit
1470
1471 Set up a socket for receiving connection requests. The integer argument
1472 is the maximal number of pending requests.
1473
1474
1475
1476 type shutdown_command =
1477 | SHUTDOWN_RECEIVE (* Close for receiving *)
1478 | SHUTDOWN_SEND (* Close for sending *)
1479 | SHUTDOWN_ALL (* Close both *)
1480
1481
1482 The type of commands for shutdown .
1483
1484
1485
1486
1487 val shutdown : file_descr -> shutdown_command -> unit
1488
1489 Shutdown a socket connection. SHUTDOWN_SEND as second argument causes
1490 reads on the other end of the connection to return an end-of-file con‐
1491 dition. SHUTDOWN_RECEIVE causes writes on the other end of the connec‐
1492 tion to return a closed pipe condition ( SIGPIPE signal).
1493
1494
1495
1496
1497 val getsockname : file_descr -> sockaddr
1498
1499 Return the address of the given socket.
1500
1501
1502
1503
1504 val getpeername : file_descr -> sockaddr
1505
1506 Return the address of the host connected to the given socket.
1507
1508
1509
1510 type msg_flag =
1511 | MSG_OOB
1512 | MSG_DONTROUTE
1513 | MSG_PEEK (* The flags for Unix.recv , Unix.recvfrom , Unix.send and
1514 Unix.sendto . *)
1515
1516
1517
1518
1519
1520 val recv : file_descr -> string -> int -> int -> msg_flag list -> int
1521
1522 Receive data from a connected socket.
1523
1524
1525
1526
1527 val recvfrom : file_descr -> string -> int -> int -> msg_flag list ->
1528 int * sockaddr
1529
1530 Receive data from an unconnected socket.
1531
1532
1533
1534
1535 val send : file_descr -> string -> int -> int -> msg_flag list -> int
1536
1537 Send data over a connected socket.
1538
1539
1540
1541
1542 val sendto : file_descr -> string -> int -> int -> msg_flag list ->
1543 sockaddr -> int
1544
1545 Send data over an unconnected socket.
1546
1547
1548
1549
1550
1551 === Socket options ===
1552
1553
1554 type socket_bool_option =
1555 | SO_DEBUG (* Record debugging information *)
1556 | SO_BROADCAST (* Permit sending of broadcast messages *)
1557 | SO_REUSEADDR (* Allow reuse of local addresses for bind *)
1558 | SO_KEEPALIVE (* Keep connection active *)
1559 | SO_DONTROUTE (* Bypass the standard routing algorithms *)
1560 | SO_OOBINLINE (* Leave out-of-band data in line *)
1561 | SO_ACCEPTCONN (* Report whether socket listening is enabled *)
1562 | TCP_NODELAY (* Control the Nagle algorithm for TCP sockets *)
1563 | IPV6_ONLY (* Forbid binding an IPv6 socket to an IPv4 address *)
1564
1565
1566 The socket options that can be consulted with Unix.getsockopt and modi‐
1567 fied with Unix.setsockopt . These options have a boolean ( true /
1568 false ) value.
1569
1570
1571
1572 type socket_int_option =
1573 | SO_SNDBUF (* Size of send buffer *)
1574 | SO_RCVBUF (* Size of received buffer *)
1575 | SO_ERROR (* Deprecated. Use Unix.getsockopt_error instead. *)
1576 | SO_TYPE (* Report the socket type *)
1577 | SO_RCVLOWAT (* Minimum number of bytes to process for input opera‐
1578 tions *)
1579 | SO_SNDLOWAT (* Minimum number of bytes to process for output opera‐
1580 tions *)
1581
1582
1583 The socket options that can be consulted with Unix.getsockopt_int and
1584 modified with Unix.setsockopt_int . These options have an integer
1585 value.
1586
1587
1588
1589 type socket_optint_option =
1590 | SO_LINGER (* Whether to linger on closed connections that have data
1591 present, and for how long (in seconds) *)
1592
1593
1594 The socket options that can be consulted with Unix.getsockopt_optint
1595 and modified with Unix.setsockopt_optint . These options have a value
1596 of type int option , with None meaning ``disabled''.
1597
1598
1599
1600 type socket_float_option =
1601 | SO_RCVTIMEO (* Timeout for input operations *)
1602 | SO_SNDTIMEO (* Timeout for output operations *)
1603
1604
1605 The socket options that can be consulted with Unix.getsockopt_float and
1606 modified with Unix.setsockopt_float . These options have a float‐
1607 ing-point value representing a time in seconds. The value 0 means
1608 infinite timeout.
1609
1610
1611
1612
1613 val getsockopt : file_descr -> socket_bool_option -> bool
1614
1615 Return the current status of a boolean-valued option in the given
1616 socket.
1617
1618
1619
1620
1621 val setsockopt : file_descr -> socket_bool_option -> bool -> unit
1622
1623 Set or clear a boolean-valued option in the given socket.
1624
1625
1626
1627
1628 val getsockopt_int : file_descr -> socket_int_option -> int
1629
1630 Same as Unix.getsockopt for an integer-valued socket option.
1631
1632
1633
1634
1635 val setsockopt_int : file_descr -> socket_int_option -> int -> unit
1636
1637 Same as Unix.setsockopt for an integer-valued socket option.
1638
1639
1640
1641
1642 val getsockopt_optint : file_descr -> socket_optint_option -> int
1643 option
1644
1645 Same as Unix.getsockopt for a socket option whose value is an int
1646 option .
1647
1648
1649
1650
1651 val setsockopt_optint : file_descr -> socket_optint_option -> int
1652 option -> unit
1653
1654 Same as Unix.setsockopt for a socket option whose value is an int
1655 option .
1656
1657
1658
1659
1660 val getsockopt_float : file_descr -> socket_float_option -> float
1661
1662 Same as Unix.getsockopt for a socket option whose value is a float‐
1663 ing-point number.
1664
1665
1666
1667
1668 val setsockopt_float : file_descr -> socket_float_option -> float ->
1669 unit
1670
1671 Same as Unix.setsockopt for a socket option whose value is a float‐
1672 ing-point number.
1673
1674
1675
1676
1677 val getsockopt_error : file_descr -> error option
1678
1679 Return the error condition associated with the given socket, and clear
1680 it.
1681
1682
1683
1684
1685
1686 === High-level network connection functions ===
1687
1688
1689 val open_connection : sockaddr -> Pervasives.in_channel * Perva‐
1690 sives.out_channel
1691
1692 Connect to a server at the given address. Return a pair of buffered
1693 channels connected to the server. Remember to call Pervasives.flush on
1694 the output channel at the right times to ensure correct synchroniza‐
1695 tion.
1696
1697
1698
1699
1700 val shutdown_connection : Pervasives.in_channel -> unit
1701
1702 ``Shut down'' a connection established with Unix.open_connection ; that
1703 is, transmit an end-of-file condition to the server reading on the
1704 other side of the connection.
1705
1706
1707
1708
1709 val establish_server : (Pervasives.in_channel -> Pervasives.out_channel
1710 -> unit) -> sockaddr -> unit
1711
1712 Establish a server on the given address. The function given as first
1713 argument is called for each connection with two buffered channels con‐
1714 nected to the client. A new process is created for each connection. The
1715 function Unix.establish_server never returns normally.
1716
1717
1718
1719
1720
1721 === Host and protocol databases ===
1722
1723
1724 type host_entry = {
1725 h_name : string ;
1726 h_aliases : string array ;
1727 h_addrtype : socket_domain ;
1728 h_addr_list : inet_addr array ;
1729 }
1730
1731
1732 Structure of entries in the hosts database.
1733
1734
1735
1736 type protocol_entry = {
1737 p_name : string ;
1738 p_aliases : string array ;
1739 p_proto : int ;
1740 }
1741
1742
1743 Structure of entries in the protocols database.
1744
1745
1746
1747 type service_entry = {
1748 s_name : string ;
1749 s_aliases : string array ;
1750 s_port : int ;
1751 s_proto : string ;
1752 }
1753
1754
1755 Structure of entries in the services database.
1756
1757
1758
1759
1760 val gethostname : unit -> string
1761
1762 Return the name of the local host.
1763
1764
1765
1766
1767 val gethostbyname : string -> host_entry
1768
1769 Find an entry in hosts with the given name, or raise Not_found .
1770
1771
1772
1773
1774 val gethostbyaddr : inet_addr -> host_entry
1775
1776 Find an entry in hosts with the given address, or raise Not_found .
1777
1778
1779
1780
1781 val getprotobyname : string -> protocol_entry
1782
1783 Find an entry in protocols with the given name, or raise Not_found .
1784
1785
1786
1787
1788 val getprotobynumber : int -> protocol_entry
1789
1790 Find an entry in protocols with the given protocol number, or raise
1791 Not_found .
1792
1793
1794
1795
1796 val getservbyname : string -> string -> service_entry
1797
1798 Find an entry in services with the given name, or raise Not_found .
1799
1800
1801
1802
1803 val getservbyport : int -> string -> service_entry
1804
1805 Find an entry in services with the given service number, or raise
1806 Not_found .
1807
1808
1809
1810 type addr_info = {
1811 ai_family : socket_domain ; (* Socket domain *)
1812 ai_socktype : socket_type ; (* Socket type *)
1813 ai_protocol : int ; (* Socket protocol number *)
1814 ai_addr : sockaddr ; (* Address *)
1815 ai_canonname : string ; (* Canonical host name *)
1816 }
1817
1818
1819 Address information returned by Unix.getaddrinfo .
1820
1821
1822
1823 type getaddrinfo_option =
1824 | AI_FAMILY of socket_domain (* Impose the given socket domain *)
1825 | AI_SOCKTYPE of socket_type (* Impose the given socket type *)
1826 | AI_PROTOCOL of int (* Impose the given protocol *)
1827 | AI_NUMERICHOST (* Do not call name resolver, expect numeric IP
1828 address *)
1829 | AI_CANONNAME (* Fill the ai_canonname field of the result *)
1830 | AI_PASSIVE (* Set address to ``any'' address for use with Unix.bind
1831 *)
1832
1833
1834 Options to Unix.getaddrinfo .
1835
1836
1837
1838
1839 val getaddrinfo : string -> string -> getaddrinfo_option list ->
1840 addr_info list
1841
1842
1843 getaddrinfo host service opts returns a list of Unix.addr_info records
1844 describing socket parameters and addresses suitable for communicating
1845 with the given host and service. The empty list is returned if the
1846 host or service names are unknown, or the constraints expressed in opts
1847 cannot be satisfied.
1848
1849
1850 host is either a host name or the string representation of an IP
1851 address. host can be given as the empty string; in this case, the
1852 ``any'' address or the ``loopback'' address are used, depending whether
1853 opts contains AI_PASSIVE . service is either a service name or the
1854 string representation of a port number. service can be given as the
1855 empty string; in this case, the port field of the returned addresses is
1856 set to 0. opts is a possibly empty list of options that allows the
1857 caller to force a particular socket domain (e.g. IPv6 only or IPv4
1858 only) or a particular socket type (e.g. TCP only or UDP only).
1859
1860
1861
1862 type name_info = {
1863 ni_hostname : string ; (* Name or IP address of host *)
1864 ni_service : string ;
1865 }
1866
1867
1868 Name of service or port number
1869
1870
1871
1872
1873
1874 === Host and service information returned by Unix.getnameinfo. ===
1875
1876
1877 type getnameinfo_option =
1878 | NI_NOFQDN (* Do not qualify local host names *)
1879 | NI_NUMERICHOST (* Always return host as IP address *)
1880 | NI_NAMEREQD (* Fail if host name cannot be determined *)
1881 | NI_NUMERICSERV (* Always return service as port number *)
1882 | NI_DGRAM (* Consider the service as UDP-based instead of the
1883 default TCP *)
1884
1885
1886 Options to Unix.getnameinfo .
1887
1888
1889
1890
1891 val getnameinfo : sockaddr -> getnameinfo_option list -> name_info
1892
1893
1894 getnameinfo addr opts returns the host name and service name corre‐
1895 sponding to the socket address addr . opts is a possibly empty list of
1896 options that governs how these names are obtained. Raise Not_found if
1897 an error occurs.
1898
1899
1900
1901
1902
1903 === Terminal interface ===
1904
1905
1906 === The following functions implement the POSIX standard terminal
1907 interface. They provide control over asynchronous communication ports
1908 and pseudo-terminals. Refer to the termios man page for a complete
1909 description. ===
1910
1911
1912 type terminal_io = {
1913
1914 mutable c_ignbrk : bool ; (* Ignore the break condition. *)
1915
1916 mutable c_brkint : bool ; (* Signal interrupt on break condition. *)
1917
1918 mutable c_ignpar : bool ; (* Ignore characters with parity errors. *)
1919
1920 mutable c_parmrk : bool ; (* Mark parity errors. *)
1921
1922 mutable c_inpck : bool ; (* Enable parity check on input. *)
1923
1924 mutable c_istrip : bool ; (* Strip 8th bit on input characters. *)
1925
1926 mutable c_inlcr : bool ; (* Map NL to CR on input. *)
1927
1928 mutable c_igncr : bool ; (* Ignore CR on input. *)
1929
1930 mutable c_icrnl : bool ; (* Map CR to NL on input. *)
1931
1932 mutable c_ixon : bool ; (* Recognize XON/XOFF characters on input. *)
1933
1934 mutable c_ixoff : bool ; (* Emit XON/XOFF chars to control input flow.
1935 *)
1936
1937 mutable c_opost : bool ; (* Enable output processing. *)
1938
1939 mutable c_obaud : int ; (* Output baud rate (0 means close connec‐
1940 tion). *)
1941
1942 mutable c_ibaud : int ; (* Input baud rate. *)
1943
1944 mutable c_csize : int ; (* Number of bits per character (5-8). *)
1945
1946 mutable c_cstopb : int ; (* Number of stop bits (1-2). *)
1947
1948 mutable c_cread : bool ; (* Reception is enabled. *)
1949
1950 mutable c_parenb : bool ; (* Enable parity generation and detection.
1951 *)
1952
1953 mutable c_parodd : bool ; (* Specify odd parity instead of even. *)
1954
1955 mutable c_hupcl : bool ; (* Hang up on last close. *)
1956
1957 mutable c_clocal : bool ; (* Ignore modem status lines. *)
1958
1959 mutable c_isig : bool ; (* Generate signal on INTR, QUIT, SUSP. *)
1960
1961 mutable c_icanon : bool ; (* Enable canonical processing (line buffer‐
1962 ing and editing) *)
1963
1964 mutable c_noflsh : bool ; (* Disable flush after INTR, QUIT, SUSP. *)
1965
1966 mutable c_echo : bool ; (* Echo input characters. *)
1967
1968 mutable c_echoe : bool ; (* Echo ERASE (to erase previous character).
1969 *)
1970
1971 mutable c_echok : bool ; (* Echo KILL (to erase the current line). *)
1972
1973 mutable c_echonl : bool ; (* Echo NL even if c_echo is not set. *)
1974
1975 mutable c_vintr : char ; (* Interrupt character (usually ctrl-C). *)
1976
1977 mutable c_vquit : char ; (* Quit character (usually ctrl-\). *)
1978
1979 mutable c_verase : char ; (* Erase character (usually DEL or ctrl-H).
1980 *)
1981
1982 mutable c_vkill : char ; (* Kill line character (usually ctrl-U). *)
1983
1984 mutable c_veof : char ; (* End-of-file character (usually ctrl-D). *)
1985
1986 mutable c_veol : char ; (* Alternate end-of-line char. (usually none).
1987 *)
1988
1989 mutable c_vmin : int ; (* Minimum number of characters to read before
1990 the read request is satisfied. *)
1991
1992 mutable c_vtime : int ; (* Maximum read wait (in 0.1s units). *)
1993
1994 mutable c_vstart : char ; (* Start character (usually ctrl-Q). *)
1995
1996 mutable c_vstop : char ; (* Stop character (usually ctrl-S). *)
1997 }
1998
1999
2000
2001
2002
2003 val tcgetattr : file_descr -> terminal_io
2004
2005 Return the status of the terminal referred to by the given file
2006 descriptor.
2007
2008
2009
2010 type setattr_when =
2011 | TCSANOW
2012 | TCSADRAIN
2013 | TCSAFLUSH
2014
2015
2016
2017
2018
2019 val tcsetattr : file_descr -> setattr_when -> terminal_io -> unit
2020
2021 Set the status of the terminal referred to by the given file descrip‐
2022 tor. The second argument indicates when the status change takes place:
2023 immediately ( TCSANOW ), when all pending output has been transmitted (
2024 TCSADRAIN ), or after flushing all input that has been received but not
2025 read ( TCSAFLUSH ). TCSADRAIN is recommended when changing the output
2026 parameters; TCSAFLUSH , when changing the input parameters.
2027
2028
2029
2030
2031 val tcsendbreak : file_descr -> int -> unit
2032
2033 Send a break condition on the given file descriptor. The second argu‐
2034 ment is the duration of the break, in 0.1s units; 0 means standard
2035 duration (0.25s).
2036
2037
2038
2039
2040 val tcdrain : file_descr -> unit
2041
2042 Waits until all output written on the given file descriptor has been
2043 transmitted.
2044
2045
2046
2047 type flush_queue =
2048 | TCIFLUSH
2049 | TCOFLUSH
2050 | TCIOFLUSH
2051
2052
2053
2054
2055
2056 val tcflush : file_descr -> flush_queue -> unit
2057
2058 Discard data written on the given file descriptor but not yet transmit‐
2059 ted, or data received but not yet read, depending on the second argu‐
2060 ment: TCIFLUSH flushes data received but not read, TCOFLUSH flushes
2061 data written but not transmitted, and TCIOFLUSH flushes both.
2062
2063
2064
2065 type flow_action =
2066 | TCOOFF
2067 | TCOON
2068 | TCIOFF
2069 | TCION
2070
2071
2072
2073
2074
2075 val tcflow : file_descr -> flow_action -> unit
2076
2077 Suspend or restart reception or transmission of data on the given file
2078 descriptor, depending on the second argument: TCOOFF suspends output,
2079 TCOON restarts output, TCIOFF transmits a STOP character to suspend
2080 input, and TCION transmits a START character to restart input.
2081
2082
2083
2084
2085 val setsid : unit -> int
2086
2087 Put the calling process in a new session and detach it from its con‐
2088 trolling terminal.
2089
2090
2091
2092
2093
2094
2095OCamldoc 2010-01-29 Unix(3)