libuv bindings
Library uwt-base
Module Uwt_base . Misc
type timeval = {
sec : int;
usec : int;
type rusage = {
utime : timeval;(*

user CPU time used

stime : timeval;(*

system CPU time used

maxrss : int64;(*

maximum resident set size

ixrss : int64;(*

integral shared memory size (X)

idrss : int64;(*

integral unshared data size (X)

isrss : int64;(*

integral unshared stack size (X)

minflt : int64;(*

page reclaims (soft page faults) (X)

majflt : int64;(*

page faults (hard page faults)

nswap : int64;(*

swaps (X)

inblock : int64;(*

block input operations

outblock : int64;(*

block output operations

msgsnd : int64;(*

IPC messages sent (X)

msgrcv : int64;(*

IPC messages received (X)

nsignals : int64;(*

signals received (X)

nvcsw : int64;(*

voluntary context switches (X)

nivcsw : int64;(*

involuntary context switches (X)


Data type for resource usage results. Members marked with (X) are unsupported on Windows.

type cpu_times = {
user : int64;
nice : int64;
sys : int64;
idle : int64;
irq : int64;
type cpu_info = {
model : string;
speed : int;
cpu_times : cpu_times;

Data type for CPU information

type interface_address = {
name : string;
phys_addr : string;
is_internal : bool;
address : sockaddr option;
netmask : sockaddr option;

Data type for interface addresses.

type handle_type =
| File
| Tty
| Pipe
| Tcp
| Udp
| Unknown
val guess_handle : Unix.file_descr -> handle_type

Used to detect what type of stream should be used with a given file descriptor. Usually this will be used during initialization to guess the type of the stdio streams.

For isatty(3) equivalent functionality use this function and test for UV_TTY.

val resident_set_memory : unit -> int64 uv_result

Gets the resident set size (RSS) for the current process.

val resident_set_memory_exn : unit -> int64
val uptime : unit -> float uv_result

Gets the current system uptime.

val uptime_exn : unit -> float
val getrusage : unit -> rusage uv_result

Gets the resource usage measures for the current process. On Windows not all fields are set

val getrusage_exn : unit -> rusage
val cpu_info : unit -> cpu_info array uv_result

Gets information about the CPUs on the system.

val cpu_info_exn : unit -> cpu_info array
val interface_addresses : unit -> interface_address array uv_result

Gets address information about the network interfaces on the system.

val interface_addresses_exn : unit -> interface_address array
val load_avg : unit -> float * float * float

Gets the load average. Returns 0,0,0 on Windows

val ip4_addr : string -> int -> sockaddr uv_result

Convert a string containing an IPv4 addresses to a binary structure.

val ip4_addr_exn : string -> int -> sockaddr
val ip4_name : sockaddr -> string uv_result

Convert a binary structure containing an IPv4 address to a string.

val ip4_name_exn : sockaddr -> string
val ip6_addr : string -> int -> sockaddr uv_result

Convert a string containing an IPv6 addresses to a binary structure.

val ip6_addr_exn : string -> int -> sockaddr
val ip6_name : sockaddr -> string uv_result

Convert a binary structure containing an IPv6 address to a string.

val ip6_name_exn : sockaddr -> string
val get_total_memory : unit -> int64

Gets memory information (in bytes).

val hrtime : unit -> int64

Returns the current high-resolution real time. This is expressed in nanoseconds. It is relative to an arbitrary time in the past. It is not related to the time of day and therefore not subject to clock drift. The primary use is for measuring performance between intervals.

Note: Not every platform can support nanosecond resolution; however, this value will always be in nanoseconds.

type version = {
major : int;
minor : int;
patch : int;
val version : unit -> version

libuv version used

val version_raw : unit -> int
val version_string : unit -> string

Many of the functions below are not thread safe and might block. Functions like cwd are useful nevertheless, if you target windows. Unlike Sys.getcwd() they return UTF8-encoded names

val os_homedir : unit -> string uv_result

Gets the current user's home directory. On Windows, homedir first checks the USERPROFILE environment variable using GetEnvironmentVariableW(). If USERPROFILE is not set, GetUserProfileDirectoryW() is called.

On all other operating systems, os_homedir first checks the HOME environment variable using getenv(3). If HOME is not set, getpwuid_r(3) is called.

val os_tmpdir : unit -> string uv_result

Gets the temp directory. On Windows, uv_os_tmpdir() uses GetTempPathW(). On all other operating systems, uv_os_tmpdir() uses the first environment variable found in the ordered list TMPDIR, TMP, TEMP, and TEMPDIR. If none of these are found, the path "/tmp" is used, or, on Android, "/data/local/tmp" is used.

val get_passwd : unit -> Unix.passwd_entry uv_result

pw_passwd and pw_gecos will currently always contain an empty string. This function does work on Windows (unlike Unix.getpwnam or Unix.getwuid )

val exepath : unit -> string uv_result

like Sys.executable_name , but utf-8 encoded under windows and perhaps more reliable under niche operating systems

val cwd : unit -> string uv_result

Gets the current working directory

val chdir : string -> Int_result.unit

Changes the current working directory.

val getenv : string -> string uv_result

Return the value associated to a variable in the process environment. ENOENT is returned, if the variable is unbound.

val putenv : key:string -> data:string -> Int_result.unit

putenv ~key ~data sets the value associated to a variable in the process environment. key is the name of the environment variable, and data its new associated value.

val unsetenv : string -> Int_result.unit

Deletes the environment variable specified by name. If no such environment variable exists, this function returns successfully.

val getppid : unit -> Int_result.int

Returns the parent process ID. Similar to Unix.getppid, but also works under Windows

The following two functions don't work reliable, especially with byte code.

val set_process_title : string -> Int_result.unit

Sets the process title. It won't necessary report an error, if it fails

val get_process_title : unit -> string uv_result
val setpriority : pid:int -> priority:int -> Int_result.unit

Sets the scheduling priority of the process specified by `pid`. The `priority` value range is between -20 (high priority) and 19 (low priority).

On Windows, this function utilizes `SetPriorityClass()`. The `priority` argument is mapped to a Windows priority class. When retrieving the process priority, the result will not necessarily equal the exact value of `priority`.

val setpriority_exn : pid:int -> priority:int -> unit
val getpriority : int -> int uv_result

Retrieves the scheduling priority of the process specified by `pid`. The returned value of `priority` is between -20 (high priority) and 19 (low priority).

val getpriority_exn : int -> int
val getpid : unit -> int uv_result

Returns the current process ID. Useful for Windows. Unix.getpid doesn't return the current Process Id. See: https://caml.inria.fr/mantis/view.php?id=4034

val getpid_exn : unit -> int