adjtimex() - Unix,Linux系統呼叫 - 技術教學
Tutorials Point


  Unix初學者指南
  Unix Shell程式設計
  高階Unix
  Unix有用參考資料
  Unix有用資源
  精選閱讀

版權所有 © 2014 tutorialspoint



  首頁     參考資料     討論論壇     關於TP  

adjtimex() - Unix,Linux系統呼叫


previous next AddThis Social Bookmark Button

廣告

名稱

adjtimex - 調整核心時鐘

概要

#include <sys/timex.h>
int adjtimex(struct timex *buf); 

描述

Linux使用David L. Mills的時鐘調整演算法(參見RFC 1305)。系統呼叫adjtimex() 讀取並可選地設定此演算法的調整引數。它接收指向timex 結構體的指標,根據欄位值更新核心引數,並返回包含當前核心值的相同結構體。此結構體宣告如下:

struct timex {
    int modes;           /* mode selector */
    long offset;         /* time offset (usec) */
    long freq;           /* frequency offset (scaled ppm) */
    long maxerror;       /* maximum error (usec) */
    long esterror;       /* estimated error (usec) */
    int status;          /* clock command/status */
    long constant;       /* pll time constant */
    long precision;      /* clock precision (usec) (read only) */
    long tolerance;      /* clock frequency tolerance (ppm)
                            (read only) */
    struct timeval time; /* current time (read only) */
    long tick;           /* usecs between clock ticks */
};

modes欄位確定要設定哪些引數(如果有)。它可以包含以下位的按位或組合:

#define ADJ_OFFSET            0x0001 /* time offset */
#define ADJ_FREQUENCY         0x0002 /* frequency offset */
#define ADJ_MAXERROR          0x0004 /* maximum time error */
#define ADJ_ESTERROR          0x0008 /* estimated time error */
#define ADJ_STATUS            0x0010 /* clock status */
#define ADJ_TIMECONST         0x0020 /* pll time constant */
#define ADJ_TICK              0x4000 /* tick value */
#define ADJ_OFFSET_SINGLESHOT 0x8001 /* old-fashioned adjtime() */

普通使用者被限制為mode 的零值。只有超級使用者可以設定任何引數。

返回值

成功時,adjtimex() 返回時鐘狀態。

#define TIME_OK   0 /* clock synchronized */
#define TIME_INS  1 /* insert leap second */
#define TIME_DEL  2 /* delete leap second */
#define TIME_OOP  3 /* leap second in progress */
#define TIME_WAIT 4 /* leap second has occurred */
#define TIME_BAD  5 /* clock not synchronized */

失敗時,adjtimex() 返回 -1 並設定errno

錯誤

標籤描述
EFAULT buf 不指向可寫記憶體。
EINVAL 嘗試將buf.offset 設定為 -131071 到 +131071 之外的值,或將buf.status 設定為上面列出的值以外的值,或將buf.tick 設定為 900000/HZ 到 1100000/HZ 之外的值,其中HZ 是系統定時器中斷頻率。
EPERM buf.mode 非零且呼叫者許可權不足。在 Linux 下,需要CAP_SYS_TIME 許可權。

符合標準

adjtimex() 是 Linux 特有的,不應在旨在可移植的程式中使用。有關更可移植但靈活性較低的方法,請參見adjtime(3),用於調整系統時鐘。

參見



previous next Printer Friendly

廣告


  

廣告



廣告
© . All rights reserved.