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.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

AGILE學習手冊 | SCRUM、XP、精實和看板方法

AGILE學習手冊 | SCRUM、XP、精實和看板方法

Andrew Stellman, Jennifer Greene
管理Kubernetes

管理Kubernetes

Brendan Burns, Craig Tracey
算法技术手册(原书第2 版)

算法技术手册(原书第2 版)

George T.Heineman, Gary Pollice, Stanley Selkow

Publisher Resources

ISBN: 9789862769812