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系統程式設計 第二版
進階的行程管理
|
195
器密集型應用程式的開銷是用戶自己的責任,而不是個別應用程式的責任。用戶可透過
nice
這個 shell 命令(本章稍後會討論到)為應用程式的效能設定其相對優先值。
行程優先權
這一節所探討的內容適合正常、非即時的行程。即時行程需要使用不同
的排班規則,以及不同的優先權系統。本章稍後會探討即時系統的相關
議題。
Linux 不會隨意對行程進行排班。事實上,應用程式會被指定
優先權
priority
),優先
權會對行程可運行多久時間造成影響:前面提到,分配給行程的處理器時間比列,會經
由它的 nice 值加上權重。以往,Unix 將優先權稱為
友善值
nice value
),因為友善值背
後的概念是透過調低一個行程的優先權來「善待」(be nice)系統上其他行程,這讓其
他行程得以使用較多之系統的處理器時間。
友善值的有效範圍從 -20 19(包括 -20 19),而且預設值為 0。你可能會有點困
惑,一個行程的友善值越低,則它的優先權就越高,而且它的時段也越大;反過來說,
友善值越高,則行程的優先權就越低,而且它的時段也越小。因此調高一個行程的友善
值就等於善待系統上的其他行程。但是以數字來看的確令人混淆。當我們說一個行程具
有「高優先權」,我們的意思是說,相較於優先權較低的行程,它可以運行比較久的時
間,但此類行程將具有較低的友善值。
nice()
Linux 提供了若干系統呼叫,可用於取得以及設定行程的友善值。
nice()
是其中最簡單
的一個:
#include <unistd.h> ...
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