Interface to Linux-specific system calls
#
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 | *) |
: 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)
sendfile ?pos ?len ~fd sock
sends mmap-able data from file
descriptor fd
to socket sock
using offset pos
and length len
.
EAGAIN
.
Unix_error
on Unix-errors.
fd
gettcpopt_bool sock opt
opt
for socket sock
.
settcpopt_bool sock opt v
sets the current value of the boolean
TCP socket option opt
for socket sock
to value v
.
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.
Some bytes_written
or None
if the operation would have blocked.
String.length buf - pos
Invalid_argument
if the designated buffer range is invalid.
Unix_error
on Unix-errors.
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.
String.length buf - pos
Invalid_argument
if the designated buffer range is invalid.
Unix_error
on Unix-errors.
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.
Some bytes_written
or None
if the
operation would have blocked.
Invalid_argument
if the designated ranges are invalid.
Unix_error
on Unix-errors.
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.
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.
pr_get_name ()
gets the name of the executing thread. The name is
at most 16 bytes long.
file_descr_realpath fd
fd
.
Unix_error
on errors.
out_channel_realpath oc
oc
.
Unix_error
on errors.
in_channel_realpath ic
ic
.
Unix_error
on errors.
cores ()
get_terminal_size ()
(rows, cols)
, the number of rows and
columns of the terminal.
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.
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)".
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
.
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
.
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
.