實用技巧:Linux下時間延遲以及延緩操作

來源:互聯網
上載者:User

 

1、在核心中計時的頭函數是#include

2、Hz符號指出每秒鐘產生的時鐘滴答數,也就是1秒鐘產生的時間中斷。

3、#include

volatile unsigned long jiffies 用這個變數來度量時間的變化。

4、int time_after(unsigned long a, unsigned long b)

int time_before(unsigned long a, unsigned long b)

這些布林運算式以安全的方式比較jiffies的數值,無需考慮計時器溢出的問題。

5、jiffies表示的時間和其他表示方法之間的數值轉換:

unsigned long timespec_to_jiffies(struct timespec *value);void jiffies_to_timespec(unsigned long jiffies, struct timespec *value);unsigned long timeval_to_jiffies(struct timeval *value);void jiffies_to_timeval(unsigned long jiffies, struct timeval *value);

(每次總是記不住,這次寫到blog上以備後患)其中timespec和timeval是linux系統中時鐘時間的結構:

struct timeval { time_t tv_sec; /* seconds */ suseconds_t tv_usec; /* microseconds */ };struct timespec { long int tv_sec; long int tv_nsec; };

使用這個結構的標頭檔在#include 中,一般常用到的函數是:

int gettimeofday(struct timeval *tv, struct timezone *tz);

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.