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系統程式設計 第二版
392
|
第十一章
時間的資料結構
Unix 系統發展的同時,為時間管理實現了它們自己的介面,有多種資料結構用來表
示看似簡單的時間概念。這些資料結構包括簡單的整數以及各種多欄位的結構。探討實
際的介面之前,讓我們先來瞭解這些資料結構。
原始的表示法
time_t
(定義於標頭檔
<time.h>
)是其中最簡單的資料結構。
time_t
是一個不透明的型
別(opaque type)。然而,在多數 Unix 系統上,包括 Linux,此型別只是 C 語言之
long
型別的
typedef
typedef long time_t;
time_t
代表自紀元後已過去的秒數。典型的反應是『發生溢位之前,它就會被廢棄不
用!』事實上,它的壽命可能會比你所預期的還久,儘管有大量的 Unix 系統仍在使用
它,但是它的確將溢位。由於是一個 32-bit
long
型別,
time_t
至多可以表示自紀元後
過去了 2,147,483,647 秒。這意味我們將於 2038 年再度遭遇 Y2K 的窘境!然而,幸運
的是,等到 2038-01-18 22:14:07 來臨時,多數的系統與軟體將會使用 64-bit 的時間值。
然而現在是:微秒的精確度
time_t
有關的另一個議題是,一秒之內會發生許多次。
timeval
結構用於擴充
time_t
加入了微秒的精確度。此結構,定義於標頭檔
<sys/time.h>
,如下所示:
#include <sys/time.h>
struct timeval {
time_t tv_sec; /* seconds ...
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