Skip to Content
For Enterprise
For Government
For Higher Ed
For Individuals
For Marketing
For Enterprise
For Government
For Higher Ed
For Individuals
For Marketing
Explore Skills
Cloud Computing
Microsoft Azure
Amazon Web Services (AWS)
Google Cloud
Cloud Migration
Cloud Deployment
Cloud Platforms
Data Engineering
Data Warehouse
SQL
Apache Spark
Microsoft SQL Server
MySQL
Kafka
Data Lake
Streaming & Messaging
NoSQL Databases
Relational Databases
Data Science
Pandas
R
MATLAB
SAS
D3
Power BI
Tableau
Statistics
Exploratory Data Analysis
Data Visualization
AI & ML
Generative AI
Machine Learning
Artificial Intelligence (AI)
Deep Learning
Reinforcement Learning
Natural Language Processing
TensorFlow
Scikit-Learn
Hyperparameter Tuning
MLOps
Programming Languages
Java
JavaScript
Spring
Python
Go
C#
C++
C
Swift
Rust
Functional Programming
Software Architecture
Object-Oriented
Distributed Systems
Domain-Driven Design
Architectural Patterns
IT/Ops
Kubernetes
Docker
GitHub
Terraform
Continuous Delivery
Continuous Integration
Database Administration
Computer Networking
Operating Systems
IT Certifications
Security
Network Security
Application Security
Incident Response
Zero Trust Model
Disaster Recovery
Penetration Testing / Ethical Hacking
Governance
Malware
Security Architecture
Security Engineering
Security Certifications
Design
Web Design
Graphic Design
Interaction Design
Film & Video
User Experience (UX)
Design Process
Design Tools
Business
Agile
Project Management
Product Management
Marketing
Human Resources
Finance
Team Management
Business Strategy
Digital Transformation
Organizational Leadership
Soft Skills
Professional Communication
Emotional Intelligence
Presentation Skills
Innovation
Critical Thinking
Public Speaking
Collaboration
Personal Productivity
Confidence / Motivation
Features
All features
Verifiable skills
AI Academy
Courses
Certifications
Interactive learning
Live events
Superstreams
Answers
Insights reporting
Radar Blog
Buy Courses
Plans
Sign In
Try Now
O'Reilly Platform
book
LINUX系統程式設計 第二版
by
Robert Love
December 2013
Intermediate to advanced
496 pages
8h 57m
Chinese
GoTop Information, Inc.
Content preview from
LINUX系統程式設計 第二版
檔案
I/O
|
47
sync()
的唯一應用就是實作
sync
公用程式。應用程式應該使用
fsync()
與
fdatasync()
把必要之「檔案描述器」的資料提交給磁碟。注意,在忙碌的系統上,
sync()
可能需要
花幾分鐘或更長的時間才會完成。
O_SYNC
旗標
把
O_SYNC
旗標傳遞給
open()
,代表所開啟之檔案的所有
I/O
都需要同步:
int fd;
fd = open (file, O_WRONLY | O_SYNC);
if (fd ==
−
1) {
perror ("open");
return
−
1;
}
讀取要求總是需要同步。否則,將無法得知緩衝區中供讀取的資料是否正確。然而,如
先前所述,
write()
的呼叫通常不需要同步。從此呼叫返回與資料是否已提交給磁碟並
無關係。
O_SYNC
旗標可用於建立此關係,確保
write()
的呼叫會進行
I/O
的同步。
正如其名,
O_SYNC
的作用是:每次
write()
操作之後及從呼叫返回之前自動呼叫
fsync()
。然而,
Linux
核心所實作的
O_SYNC
效率比較高一點。
O_SYNC
會讓寫入操作的用戶時間與核心時間(分別代表在用戶空間與核心空間中所花的
時間)略微變差。此外,這取決於被寫入之檔案的大小,
O_SYNC
可能會由於此過程所招
致的所有
I/O
等待時間(等待
I/O
完成所花的時間)讓總耗費時間(
total elapsed time
)
增加一或兩個數量級。這會增加巨大的成本,所以除非不得已,否則最好不要使用同步
I/O
。
通常,應用程式需要使用 ...
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科學研究的美學
Juan Nunez-Iglesias, Stéfan van der Walt, Harriet Dashnow
成為卓越程式設計師的38項必修法則
Pete Goodliffe
深入理解運算原理|從簡單的機器到無所不能的程式
Tom Stuart
C++语言导学(原书第2版)
本贾尼 斯特劳斯特鲁普
Publisher Resources
ISBN: 9789862769812