clockgettime
Clock_gettime is a POSIX API function used to obtain the current value of a specified clock. It takes a clock identifier and a pointer to a timespec structure, which is filled with the time data. The timespec contains tv_sec (the seconds portion) and tv_nsec (the nanoseconds portion). The nanoseconds field represents fractional seconds with high precision. For CLOCK_REALTIME the seconds are counted from the Unix epoch; for other clocks the origin is implementation-defined or unspecified.
Common clocks include CLOCK_REALTIME (wall-clock time), CLOCK_MONOTONIC (steady clock not affected by system time changes), CLOCK_PROCESS_CPUTIME_ID
The function returns 0 on success and -1 on error, with errno set to indicate the failure.
Usage considerations include choosing the appropriate clock for the task: use CLOCK_REALTIME for timestamps tied to
Implementation notes: include <time.h> and link as required by the target platform (some older systems required
---