module UnixExtras: sig end
Supplements to the Unix module
val make_daemon : (unit -> unit) -> bool -> unit
Runs f in a new daemon process. The calling process will exit
if the second argument is true.
For example:
let _ = UnixExtras.make_daemon server_func true
will start a new process and run server_func
in it, while the original
process will exit. See Stevens, Advanced Programming in the Unix Environment
for details.
val send_file : src:Unix.file_descr -> dest:Unix.file_descr -> start:int -> len:int -> int
Reads len
bytes from the src
descr with offset start
and
copies them to the dest
descr. Currently implemented only for Linux
and FreeBSD. The FreeBSD sendfile() system call requires that dest
be
a socket.
Raises Unix_error
on failure.
val pread : Unix.file_descr -> string -> int -> int -> int
pread fd buff ofs len
is just like Unix.read
except it doesn't update the file descriptor's offset. The file must be capable of seeking.
val pwrite : Unix.file_descr -> string -> int -> int -> int
pwrite fd buff ofs len
is just like Unix.write
except it doesn't update the file descriptor's offset. The file must be capable of seeking.
val getservent : unit -> Unix.service_entry
Same as the Unix getservent(3)
val setservent : bool -> unit
Same as the Unix setservent(3)
val endservent : unit -> unit
Same as the Unix endservent(3)
val listdir : Unix.dir_handle -> string list
Returns a list of all filenames that can be read from a dirhandle
val tilde_expand : string -> string
Does shell-like tilde expansion of a file path. tilde_expand
"~/foo"
returns the home directory of the current user (Via
Unix.getlogin
) with /foo appended to it. "~foo/bar" does the same
for the user foo. Anything else is returned unaltered.
Raises Not_found
if the user doesn't exist.
val mknod : string ->
Unix.file_perm -> [< `BLOCK | `CHAR ] -> major:int -> minor:int -> unit
mknod filename type ~major ~minor
makes a new character or block
special file.
Process information functions
|
type
rusage_who =
| |
RUSAGE_SELF |
| |
RUSAGE_CHILDREN |
Do we get rusage information about the calling process or its child processes?
type
rusage = {
|
ru_utime : Time.timeval ; |
|
ru_stime : Time.timeval ; |
|
ru_maxrss : int ; |
|
ru_ixrss : int ; |
|
ru_idrss : int ; |
|
ru_isrss : int ; |
|
ru_minflt : int ; |
|
ru_majflt : int ; |
|
ru_nswap : int ; |
|
ru_inblock : int ; |
|
ru_oublock : int ; |
|
ru_msgsnd : int ; |
|
ru_msgrcv : int ; |
|
ru_nsignals : int ; |
|
ru_nvcsw : int ; |
|
ru_nivcsw : int ; |
}
The structure retured by getrusage
. Not all OSes track all
fields. Notably, Linux only uses ru_rutime, ru_stime, ru_minflt,
ru_majflt and ru_nswap.
val getrusage : rusage_who -> rusage
Same as the Unix getrusage(2)
type
rlimit_resource =
| |
RLIMIT_CPU |
| |
RLIMIT_FSIZE |
| |
RLIMIT_DATA |
| |
RLIMIT_STACK |
| |
RLIMIT_CORE |
| |
RLIMIT_RSS |
| |
RLIMIT_NPROF |
| |
RLIMIT_NOFILE |
| |
RLIMIT_MEMLOCK |
| |
RLIMIT_AS |
The resource type to query or set with getrlimit
or setrlimit
type
rlimit = {
|
rlim_cur : int ; |
|
rlim_max : int ; |
}
The type for querying resource limits.
val getrlimit : rlimit_resource -> rlimit
Same as the Unix getrlimit(2)
val setrlimit : rlimit_resource -> rlimit -> unit
Same as the Unix setrlimit(2)
val getpgid : int -> int
Same as the Unix getpgid(2)
val setpgid : int -> int -> unit
Same as the Unix setpgid(2)
val getpgrp : unit -> int
Same as the Unix getpgrp(2)
val setpgrp : unit -> unit
Same as the Unix setpgrp(2)