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系統程式設計 第二版
62
|
第二章
之所以會把
pselect()
加入 Unix 的工具箱,背後的主要動力是增加了
sigmask
參數,其
目的在避免「等待檔案描述器」與「信號處理」(第 10 章將有深入的探討)之間的爭用
情況。假定信號處理程序(signal handler)會設定一個全域旗標(多半會這麼做),而
且行程在叫用
select()
之前會檢查此旗標。現在,假設信號是在檢查之後及呼叫之前抵
達的。應用程式可能無限期受到阻擋,而無法對所設定的旗標做出回應。
pselect()
呼叫
可以解決這個問題,其做法是為叫用
pselect()
的應用程式提供一群受阻檔的信號。受
阻擋的信號不會被處理,除非它們已不再受阻擋。一旦從
pselect()
返回,核心會回復
舊的信號遮罩(signal mask)。
直到2.6.16 版核心,
pselect()
Linux 實作並非系統呼叫,而是
glibc
所提供之
select()
的簡單包裹函式。此包裹函式可儘量避免—但是無法完全消除—產生此爭用情
況的風險。如果能夠引進真正的系統呼叫,將可完全避免爭用情況。
儘管
pselect()
中做了一些(相對較小的)改進,但是多數應用程式,無論是出於習
慣,或者是基於可移植性,仍繼續使用
select()
poll()
poll()
系統呼叫是 System V 的多工式 I/O 解決方案。它解決了
select()
的若干缺點,
然而
select()
仍舊經常被用到(同樣地,多半是出於習慣,或者是基於可移植性):
#include <poll.h>
int poll (struct ...
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