Module Posix_time2

POSIX time and clock functions.

This module provides OCaml bindings to POSIX time functions defined in time.h and sys/time.h.

It includes high-precision time structures, clock access, timers, and time conversion functions.

Time Structures

module Timespec : sig ... end

POSIX timespec: time with nanosecond precision.

module Itimerspec : sig ... end

Interval timer specification using timespec.

module Timeval : sig ... end

POSIX timeval: time with microsecond precision.

module Tm : sig ... end

POSIX broken-down time structure.

module Itimerval : sig ... end

Interval timer value using timeval.

Clock Types

type clock = [
  1. | `Realtime
    (*

    System-wide real-time clock

    *)
  2. | `Monotonic
    (*

    Monotonic clock that cannot be set

    *)
  3. | `Process_cputime
    (*

    CPU time consumed by the process

    *)
  4. | `Thread_cputime
    (*

    CPU time consumed by the thread

    *)
]

Clock identifiers for clock_gettime and related functions. See clock_getres(3).

Clock Functions

val asctime : Tm.t -> string

Convert broken-down time to a string. See asctime(3).

val clock_getres : clock -> Timespec.t

Get clock resolution. See clock_getres(3).

val clock_gettime : clock -> Timespec.t

Get current time from a clock. See clock_gettime(3).

val clock_settime : clock -> Timespec.t -> unit

Set a clock's time (requires appropriate privileges). See clock_settime(3).

val ctime : int64 -> string

Convert Unix timestamp to a date/time string. See ctime(3).

val gmtime : int64 -> Tm.t

Convert Unix timestamp to broken-down UTC time. See gmtime(3).

val localtime : int64 -> Tm.t

Convert Unix timestamp to broken-down local time. See localtime(3).

val mktime : Tm.t -> int64

Convert broken-down time to Unix timestamp. See mktime(3).

Sleep Functions

val nanosleep : Timespec.t -> unit

High-resolution sleep. See nanosleep(3).

val clock_nanosleep : absolute:bool -> clock:clock -> Timespec.t -> unit

High-resolution sleep with clock selection. See clock_nanosleep(3).

  • parameter absolute

    If true, sleep until the specified absolute time. If false, sleep for the specified duration.

  • parameter clock

    The clock to use for timing.

Interval Timers

type itimer = [
  1. | `Real
    (*

    ITIMER_REAL: decrements in real time, delivers SIGALRM

    *)
  2. | `Virtual
    (*

    ITIMER_VIRTUAL: decrements in process virtual time, delivers SIGVTALRM

    *)
  3. | `Prof
    (*

    ITIMER_PROF: decrements in process time, delivers SIGPROF

    *)
]

Interval timer types for getitimer and setitimer. See getitimer(3).

val getitimer : itimer -> Itimerval.t

Get the value of an interval timer. See getitimer(3).

val setitimer : itimer -> Itimerval.t -> Itimerval.t

Set an interval timer and return its previous value. See setitimer(3).

Time of Day

val gettimeofday : unit -> Timeval.t

Get the current time of day. See gettimeofday(3).

I/O Multiplexing

val select : Unix.file_descr list -> Unix.file_descr list -> Unix.file_descr list -> Timeval.t option -> Unix.file_descr list * Unix.file_descr list * Unix.file_descr list

Synchronous I/O multiplexing.

See select(2).

  • parameter readfds

    File descriptors to check for readability.

  • parameter writefds

    File descriptors to check for writability.

  • parameter exceptfds

    File descriptors to check for exceptions.

  • parameter timeout

    Maximum time to wait, or None to block indefinitely.

  • returns

    Triple of ready file descriptors (readable, writable, exceptions).

File Times

val utimes : last_access:Timeval.t -> last_modification:Timeval.t -> string -> unit

Set file access and modification times. See utimes(3).

  • parameter ~last_access

    date and time of last access

  • parameter ~last_modification

    date and time of last modification

  • parameter path

    Path to the file.