package uwt
This section contains miscellaneous functions that don't really belong in any other section.
type rusage = Uwt_base.Misc.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.
Data type for CPU information
type interface_address = Uwt_base.Misc.interface_address = {
name : string;
phys_addr : string;
is_internal : bool;
address : sockaddr option;
netmask : sockaddr option;
}
Data type for interface addresses.
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 uptime : unit -> float uv_result
Gets the current system uptime.
Gets the resource usage measures for the current process. On Windows not all fields are set
val getrusage_exn : unit -> rusage
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
Convert a string containing an IPv4 addresses to a binary structure.
val ip4_addr_exn : string -> int -> sockaddr
Convert a binary structure containing an IPv4 address to a string.
val ip4_name_exn : sockaddr -> string
Convert a string containing an IPv6 addresses to a binary structure.
val ip6_addr_exn : string -> int -> sockaddr
Convert a binary structure containing an IPv6 address to a string.
val ip6_name_exn : sockaddr -> string
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.
val version : unit -> version
libuv version used
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 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 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