Skip to Content
LINUX系統程式設計 第二版
book

LINUX系統程式設計 第二版

by Robert Love
December 2013
Intermediate to advanced
496 pages
8h 57m
Chinese
GoTop Information, Inc.
Content preview from LINUX系統程式設計 第二版
時間
|
423
取得一個計時器的超限運轉次數
POSIX 定義了一個介面,可用於確定特定計時器上發生超限運轉的次數(如果有的話):
#include <time.h>
int timer_getoverrun (timer_t timerid);
執行成功時,
timer_getoverrun()
會傳回「計時器初次屆滿」與「通知行程—例如經由
一個信號—計時器已屆滿」之間額外發生的計時器屆滿次數。舉例來說,在我們之前的
例子中,一個 1 ms 的計時器運轉了 10 ms,則此呼叫會傳回
9
根據 POSIX 的規定,如果超限運轉的次數等於或大於
DELAYTIMER_MAX
,則此呼叫會傳回
DELAYTIMER_MAX
。不幸的是,Linux 並未實作此行為;事實上,Linux 中,一旦計時器超
限運轉的次數超過
DELAYTIMER_MAX
,它便會回到零,重新開始。
執行失敗時,此函式會傳回
-1
以及把
errno
設定為
EINVAL
,這個唯一的錯誤狀況,代表
timerid
指定了無效的計時器。
例如:
int ret;
ret = timer_getoverrun (timer);
if (ret ==
1)
perror ("timer_getoverrun");
else if (ret == 0)
printf ("no overrun\n");
else
printf ("%d overrun(s)\n", ret);
刪除一個計時器
要刪除一個計時器很容易:
#include <time.h>
int timer_delete ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

優雅的SciPy|Python科學研究的美學

優雅的SciPy|Python科學研究的美學

Juan Nunez-Iglesias, Stéfan van der Walt, Harriet Dashnow
C++语言导学(原书第2版)

C++语言导学(原书第2版)

本贾尼 斯特劳斯特鲁普

Publisher Resources

ISBN: 9789862769812