Up

module Linux_ext

: sig

Interface to Linux-specific system calls

sysinfo

#
module Sysinfo : sig
#
type t = {
# uptime
: Span.t;(*time since boot*)
# load1
: int;(*load average over the last minute*)
# load5
: int;(*load average over the last 5 minutes*)
# load15
: int;(*load average over the last 15 minutes*)
# total_ram
: int;(*total usable main memory*)
# free_ram
: int;(*available memory size*)
# shared_ram
: int;(*amount of shared memory*)
# buffer_ram
: int;(*memory used by buffers*)
# total_swap
: int;(*total swap page size*)
# free_swap
: int;(*available swap space*)
# procs
: int;(*number of current processes*)
# totalhigh
: int;(*Total high memory size*)
# freehigh
: int;(*Available high memory size*)
# mem_unit
: int;(*Memory unit size in bytes*)
}

Result of sysinfo syscall (man 2 sysinfo)

#
val sysinfo : (unit -> t) Core_kernel.Std.Or_error.t
#
val bin_t : t Core_kernel.Std.Bin_prot.Type_class.t
#
val bin_read_t : t Core_kernel.Std.Bin_prot.Read.reader
#
val __bin_read_t__ : (int -> t) Core_kernel.Std.Bin_prot.Read.reader
#
val bin_reader_t : t Core_kernel.Std.Bin_prot.Type_class.reader
#
val bin_size_t : t Core_kernel.Std.Bin_prot.Size.sizer
#
val bin_write_t : t Core_kernel.Std.Bin_prot.Write.writer
#
val bin_writer_t : t Core_kernel.Std.Bin_prot.Type_class.writer
#
val t_of_sexp : Sexplib.Sexp.t -> t
#
val sexp_of_t : t -> Sexplib.Sexp.t
end

Filesystem functions

#
val sendfile : (?pos:int -> ?len:int -> fd:Core_unix.File_descr.t -> Core_unix.File_descr.t -> int) Core_kernel.Std.Or_error.t

sendfile ?pos ?len ~fd sock sends mmap-able data from file descriptor fd to socket sock using offset pos and length len.

Returns the number of characters actually written.
NOTE: if the returned value is unequal to what was requested (= the initial size of the data by default), the system call may have been interrupted by a signal, the source file may have been truncated during operation, or a timeout occurred on the socket during sending. It is currently impossible to find out which of the events above happened. Calling sendfile several times on the same descriptor that only partially accepted data due to a timeout will eventually lead to the unix error EAGAIN.
Raises Unix_error on Unix-errors.
default pos = 0
default len = length of data (file) associated with descriptor fd

Non-portable TCP-functionality

#
type tcp_bool_option =
# | TCP_CORK
#
val gettcpopt_bool : (Core_unix.File_descr.t -> tcp_bool_option -> bool) Core_kernel.Std.Or_error.t

gettcpopt_bool sock opt

Returns the current value of the boolean TCP socket option opt for socket sock.
#
val settcpopt_bool : (Core_unix.File_descr.t -> tcp_bool_option -> bool -> unit) Core_kernel.Std.Or_error.t

settcpopt_bool sock opt v sets the current value of the boolean TCP socket option opt for socket sock to value v.

#
val send_nonblocking_no_sigpipe : (Core_unix.File_descr.t -> ?pos:int -> ?len:int -> string -> int option) Core_kernel.Std.Or_error.t

send_nonblocking_no_sigpipe sock ?pos ?len buf tries to do a nonblocking send on socket sock given buffer buf, offset pos and length len. Prevents SIGPIPE, i.e. raise a Unix-error in that case immediately.

Returns Some bytes_written or None if the operation would have blocked.
pos default = 0
len default = String.length buf - pos
Raises Invalid_argument if the designated buffer range is invalid.
Raises Unix_error on Unix-errors.
#
val send_no_sigpipe : (Core_unix.File_descr.t -> ?pos:int -> ?len:int -> string -> int) Core_kernel.Std.Or_error.t

send_no_sigpipe sock ?pos ?len buf tries to do a blocking send on socket sock given buffer buf, offset pos and length len. Prevents SIGPIPE, i.e. raise a Unix-error in that case immediately.

Returns the number of bytes written.
pos default = 0
len default = String.length buf - pos
Raises Invalid_argument if the designated buffer range is invalid.
Raises Unix_error on Unix-errors.
#
val sendmsg_nonblocking_no_sigpipe : (Core_unix.File_descr.t -> ?count:int -> string Core_unix.IOVec.t array -> int option) Core_kernel.Std.Or_error.t

sendmsg_nonblocking_no_sigpipe sock ?count iovecs tries to do a nonblocking send on socket sock using count I/O-vectors iovecs. Prevents SIGPIPE, i.e. raises a Unix-error in that case immediately.

Returns Some bytes_written or None if the operation would have blocked.
Raises Invalid_argument if the designated ranges are invalid.
Raises Unix_error on Unix-errors.

Clock functions

#
module Clock : sig
#
type t
#
val get : (Thread.t -> t) Core_kernel.Std.Or_error.t
#
val get_time : (t -> Span.t) Core_kernel.Std.Or_error.t
#
val set_time : (t -> Span.t -> unit) Core_kernel.Std.Or_error.t
#
val get_resolution : (t -> Span.t) Core_kernel.Std.Or_error.t
#
val get_process_clock : (unit -> t) Core_kernel.Std.Or_error.t

get_process_clock the clock measuring the CPU-time of a process.

#
val get_thread_clock : (unit -> t) Core_kernel.Std.Or_error.t

get_thread_clock the clock measuring the CPU-time of the current thread.

end

Timerfd functions

#
module Timerfd : sig
#
module Clock : sig

Clock used to mark the progress of a timer.

#
type t
#
val realtime : t

Settable system-wide clock.

#
val monotonic : t

Nonsettable clock. It is not affected by manual changes to the system time.

#
val t_of_sexp : Sexplib.Sexp.t -> t
#
val sexp_of_t : t -> Sexplib.Sexp.t
#
val compare : t -> t -> int
#
val bin_t : t Core_kernel.Std.Bin_prot.Type_class.t
#
val bin_read_t : t Core_kernel.Std.Bin_prot.Read.reader
#
val __bin_read_t__ : (int -> t) Core_kernel.Std.Bin_prot.Read.reader
#
val bin_reader_t : t Core_kernel.Std.Bin_prot.Type_class.reader
#
val bin_size_t : t Core_kernel.Std.Bin_prot.Size.sizer
#
val bin_write_t : t Core_kernel.Std.Bin_prot.Write.writer
#
val bin_writer_t : t Core_kernel.Std.Bin_prot.Type_class.writer
end
#
module Flags : sig
#
type t
include Core_kernel.Std.Flags.S with type t := t
#
val nonblock : t

TFD_NONBLOCK

#
val cloexec : t

TFD_CLOEXEC

#
val sexp_of_t : t -> Sexplib.Sexp.t
end
#
type t = private Core_unix.File_descr.t
#
val to_file_descr : t -> Core_unix.File_descr.t
#
val create : (?flags:Flags.t -> Clock.t -> t) Core_kernel.Std.Or_error.t

create ?flags clock creates a new timer file descriptor. With Linux 2.6.26 or earlier flags must be empty.

#
val set : t -> [
| `At of Time.t
| `After of Span.t
] -> unit

set t when sets t to fire once, at the time specified by when.

#
val set_repeating : ?initial:[
| `At of Time.t
| `After of Span.t
] -> t -> Span.t -> unit

set_repeating ?initial t interval sets t to fire every interval starting at when.

#
val clear : t -> unit

clear t causes t to not fire any more.

#
type repeat = {
# fire_after
: Span.t;
# interval
: Span.t;
}
#
val get : t -> [
| `Not_armed
| `Fire_after of Span.t
| `Repeat of repeat
]

get t returns the current state of the timer t.

#
val t_of_sexp : Sexplib.Sexp.t -> t
#
val sexp_of_t : t -> Sexplib.Sexp.t
#
val compare : t -> t -> int
#
val bin_t : t Core_kernel.Std.Bin_prot.Type_class.t
#
val bin_read_t : t Core_kernel.Std.Bin_prot.Read.reader
#
val __bin_read_t__ : (int -> t) Core_kernel.Std.Bin_prot.Read.reader
#
val bin_reader_t : t Core_kernel.Std.Bin_prot.Type_class.reader
#
val bin_size_t : t Core_kernel.Std.Bin_prot.Size.sizer
#
val bin_write_t : t Core_kernel.Std.Bin_prot.Write.writer
#
val bin_writer_t : t Core_kernel.Std.Bin_prot.Type_class.writer
end

Parent death notifications

#
val pr_set_pdeathsig : (Signal.t -> unit) Core_kernel.Std.Or_error.t

pr_set_pdeathsig s sets the signal s to be sent to the executing process when its parent dies. NOTE: the parent may have died before or while executing this system call. To make sure that you do not miss this event, you should call [root:getppid] to get the parent process id after this system call. If the parent has died, the returned parent PID will be 1, i.e. the init process will have adopted the child. You should then either send the signal to yourself using Unix.kill, or execute an appropriate handler.

#
val pr_get_pdeathsig : (unit -> Signal.t) Core_kernel.Std.Or_error.t

pr_get_pdeathsig () get the signal that will be sent to the currently executing process when its parent dies.

Task name

#
val pr_set_name_first16 : (string -> unit) Core_kernel.Std.Or_error.t

pr_set_name_first16 name sets the name of the executing thread to name. Only the first 16 bytes in name will be used, the rest is ignored.

#
val pr_get_name : (unit -> string) Core_kernel.Std.Or_error.t

pr_get_name () gets the name of the executing thread. The name is at most 16 bytes long.

Pathname resolution

#
val file_descr_realpath : (Core_unix.File_descr.t -> string) Core_kernel.Std.Or_error.t

file_descr_realpath fd

Returns the canonicalized absolute pathname of the file associated with file descriptor fd.
Raises Unix_error on errors.
#
val out_channel_realpath : (Pervasives.out_channel -> string) Core_kernel.Std.Or_error.t

out_channel_realpath oc

Returns the canonicalized absolute pathname of the file associated with output channel oc.
Raises Unix_error on errors.
#
val in_channel_realpath : (Pervasives.in_channel -> string) Core_kernel.Std.Or_error.t

in_channel_realpath ic

Returns the canonicalized absolute pathname of the file associated with input channel ic.
Raises Unix_error on errors.

Affinity

#
val sched_setaffinity : (?pid:Core_kernel.Std.Pid.t -> cpuset:int list -> unit -> unit) Core_kernel.Std.Or_error.t
#
val sched_setaffinity_this_thread : (cpuset:int list -> unit) Core_kernel.Std.Or_error.t
#
val cores : (unit -> int) Core_kernel.Std.Or_error.t

cores ()

Returns the number of cores on the machine
#
val get_terminal_size : (unit -> int * int) Core_kernel.Std.Or_error.t

get_terminal_size ()

Returns (rows, cols), the number of rows and columns of the terminal.
#
module Priority : sig
#
type t
#
val equal : t -> t -> bool
#
val of_int : int -> t
#
val to_int : t -> int
#
val incr : t -> t
#
val decr : t -> t
#
val t_of_sexp : Sexplib.Sexp.t -> t
#
val sexp_of_t : t -> Sexplib.Sexp.t
end
#
val setpriority : (Priority.t -> unit) Core_kernel.Std.Or_error.t

Set the calling thread's priority in the linux scheduler

#
val getpriority : (unit -> Priority.t) Core_kernel.Std.Or_error.t

Get the calling thread's priority in the linux scheduler

#
val get_ipv4_address_for_interface : (string -> string) Core_kernel.Std.Or_error.t
#
val bind_to_interface : (Core_unix.File_descr.t -> [
| `Any
| `Interface_name of string
] -> unit) Core_kernel.Std.Or_error.t
#
module Epoll : sig

epoll() - a linux I/O multiplexer of the same family as select() or poll(). Its main differences are support for Edge or Level triggered notifications (We're using Level-triggered to emulate select) and much better scaling with the number of file descriptors.

See the man pages for a full description of the epoll facility.

#
module Flags : sig
#
type t

An Epoll.Flags.t is an immutable set of flags for which one can register interest for a file descriptor. It is implemented as a bitmask, and so all operations (+, -, etc.) are constant time with no allocation.

sexp_of_t produces a human-readable list of bits, e.g. "(in out)".

include Core_kernel.Std.Flags.S with type t := t
#
val none : t
#
val in_ : t
#
val out : t
#
val pri : t
#
val err : t
#
val hup : t
#
val et : t
#
val oneshot : t
#
val sexp_of_t : t -> Sexplib.Sexp.t
end
#
type t

An Epoll.t maintains a map from File_descr.t to Flags.t, where the domain is the set of file descriptors that one is interested in, and the flags associated with each file descriptor specify the types of events one is interested in being notified about for that file descriptor. Our implementation maintains a user-level table equivalent to the kernel epoll set, so that sexp_of_t produces useful human-readable information, and so that we can present our standard table interface.

An Epoll.t also has a buffer that is used to store the set of ready fds returned by calling wait.

#
val invariant : t -> unit
#
val create : (num_file_descrs:int -> max_ready_events:int -> t) Core_kernel.Std.Or_error.t

create ~num_file_descrs creates a new epoll set able to watch file descriptors in [0, num_file_descrs). Additionally, the set allocates space for reading the ready events when wait returns, allowing for up to max_ready_events to be returned in a single call to wait.

#
val close : t -> unit
#
val find : t -> Core_unix.File_descr.t -> Flags.t option

map operations

#
val find_exn : t -> Core_unix.File_descr.t -> Flags.t
#
val set : t -> Core_unix.File_descr.t -> Flags.t -> unit
#
val remove : t -> Core_unix.File_descr.t -> unit
#
val iter : t -> f:(Core_unix.File_descr.t -> Flags.t -> unit) -> unit
#
val wait : t -> timeout:[
| `Never
| `Immediately
| `After of Span.t
] -> [
| `Ok
| `Timeout
]

wait t ~timeout blocks until at least one file descriptor in t is ready for one of the events it is being watched for, or timeout passes. wait side effects t by storing the ready set in it. One can subsequently access the ready set by calling iter_ready or fold_ready.

The timeout has a granularity of one millisecond. wait rounds up the timeout to the next millisecond. E.g. a timeout of one microsecond will be rounded up to one millisecond.

Note that this method should not be considered thread safe. There is mutable state in t that will be changed by invocations to wait that cannot be prevented by mutexes around wait.

#
val iter_ready : t -> f:(Core_unix.File_descr.t -> Flags.t -> unit) -> unit

iter_ready and fold_ready iterate over the ready set computed by the last call to wait.

#
val fold_ready : t -> init:'a -> f:('a -> Core_unix.File_descr.t -> Flags.t -> 'a) -> 'a
#
val sexp_of_t : t -> Sexplib.Sexp.t
end
#
val bin_tcp_bool_option : tcp_bool_option Core_kernel.Std.Bin_prot.Type_class.t
#
val bin_read_tcp_bool_option : tcp_bool_option Core_kernel.Std.Bin_prot.Read.reader
#
val __bin_read_tcp_bool_option__ : (int -> tcp_bool_option) Core_kernel.Std.Bin_prot.Read.reader
#
val bin_reader_tcp_bool_option : tcp_bool_option Core_kernel.Std.Bin_prot.Type_class.reader
#
val bin_size_tcp_bool_option : tcp_bool_option Core_kernel.Std.Bin_prot.Size.sizer
#
val bin_write_tcp_bool_option : tcp_bool_option Core_kernel.Std.Bin_prot.Write.writer
#
val bin_writer_tcp_bool_option : tcp_bool_option Core_kernel.Std.Bin_prot.Type_class.writer
#
val tcp_bool_option_of_sexp : Sexplib.Sexp.t -> tcp_bool_option
#
val sexp_of_tcp_bool_option : tcp_bool_option -> Sexplib.Sexp.t
end