The ntp_gettime
and ntp_adjtime
functions provide an
interface to monitor and manipulate the system clock to maintain high
accuracy time. For example, you can fine tune the speed of the clock
or synchronize it with another time source.
A typical use of these functions is by a server implementing the Network Time Protocol to synchronize the clocks of multiple systems and high precision clocks.
These functions are declared in `sys/timex.h'.
struct timeval time
struct timeval
data type is described in
section Elapsed Time.
long int maxerror
ntp_adjtime
periodically, this value will reach some
platform-specific maximum value.
long int esterror
ntp_adjtime
to indicate the estimated offset of the
system clock from the true calendar time.
ntp_gettime
function sets the structure pointed to by
tptr to current values. The elements of the structure afterwards
contain the values the timer implementation in the kernel assumes. They
might or might not be correct. If they are not a ntp_adjtime
call is necessary.
The return value is 0
on success and other values on failure. The
following errno
error conditions are defined for this function:
TIME_ERROR
unsigned int modes
MOD_
.
long int offset
MOD_OFFSET
is set in modes
, the offset (and possibly other
dependent values) can be set. The offset's absolute value must not
exceed MAXPHASE
.
long int frequency
1 <<
SHIFT_USEC
. The value can be set with bit MOD_FREQUENCY
, but
the absolute value must not exceed MAXFREQ
.
long int maxerror
MOD_MAXERROR
. Unless updated via
ntp_adjtime
periodically, this value will increase steadily
and reach some platform-specific maximum value.
long int esterror
MOD_ESTERROR
.
int status
STA_
. Some of these flags can be updated using the
MOD_STATUS
bit.
long int constant
MOD_TIMECONST
.
long int precision
long int tolerance
maxerror
every
second.
struct timeval time
long int tick
long int ppsfreq
long int jitter
int shift
PPS_SHIFT
to PPS_SHIFTMAX
.
long int stabil
long int jitcnt
MAXTIME
.
long int calcnt
long int errcnt
long int stbcnt
ntp_adjtime
function sets the structure specified by
tptr to current values.
In addition, ntp_adjtime
updates some settings to match what you
pass to it in *tptr. Use the modes
element of *tptr
to select what settings to update. You can set offset
,
freq
, maxerror
, esterror
, status
,
constant
, and tick
.
modes
= zero means set nothing.
Only the superuser can update settings.
The return value is 0
on success and other values on failure. The
following errno
error conditions are defined for this function:
TIME_ERROR
EPERM
For more details see RFC1305 (Network Time Protocol, Version 3) and related documents.
Portability note: Early versions of the GNU C library did not
have this function but did have the synonymous adjtimex
.
Go to the first, previous, next, last section, table of contents.