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系統程式設計 第二版
218
|
第六章
資源限度
Linux 核心對行程加上了若干
資源限度
resource limit
)。這些資源限度是一個行程所能
耗用之核心資源的硬性上限—也就是,所能開啟的檔案數目、記憶體頁面的數目、未決
信號的數目…等等。這些限度必須嚴格實施;核心將不允許行程的資源耗用逾越硬性限
度。舉例來說,如果開啟一個檔案將導致一個行程所開啟的檔案數目逾越可用的資源限
度,則
open()
的調用會失敗。
3
Linux 提供了兩個系統呼叫可用於操作資源限度。儘管 POSIX 有將這兩個介面納入標
準,但是除了標準所規定的限度,Linux 還支援一些其他的限度。限度的檢查與設定可
分別透過
getrlimit()
setrlimit()
來進行:
#include <sys/time.h>
#include <sys/resource.h>
struct rlimit {
rlim_t rlim_cur; /* soft limit */
rlim_t rlim_max; /* hard limit */
};
int getrlimit (int resource, struct rlimit *rlim);
int setrlimit (int resource, const struct rlimit *rlim);
整數常數,例如
RLIMIT_CPU
,用於表示資源。
rlimit
結構用於表示實際的限度。此結構
定義了兩個上限值:軟性限度(soft limit)及硬性限度(hard limit)。核心會對行程實
施軟性資源限度,但是一個行程可以自由地把它的軟性限度變更成「範圍從 ...
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