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系統程式設計 第二版
記憶體管理
|
349
ENOMEM
呼叫者試圖鎖住超過
RLIMIT_MEMLOCK
資源限度所允許的頁面(見第 9 章〈上鎖限
度〉一節)。
EPERM
RLIMIT_MEMLOCK
資源限度的值為
0
,但是行程並不具
CAP_IPC_LOCK
的能力(同樣地,
見第九章〈上鎖限度〉一節)。
一個子行程無法跨越
fork()
繼承記憶體的上鎖狀態。然而,由於 Linux
位址空間的「寫入時才複製」行為,一個子行程的頁面會被有效地鎖入記
憶體,直到子行程寫入它們。
舉一個例子,假定程式會在記憶體中保存一個已解密的字串,那麼它的行程可以使用如
下的程式碼鎖住包含該字串的頁面:
int ret;
/* 'secret' 鎖入記憶體 */
ret = mlock (secret, strlen (secret));
if (ret)
perror ("mlock");
鎖住一整個位址空間
如果一個行程想要把它的整個位址空間鎖入實體記憶體,
mlock()
是一個繁瑣的介面。
對於此類用途—常見於即時應用程式— POSIX 定義了一個系統呼叫,可用於鎖住一整
個位址空間:
#include <sys/mman.h>
int mlockall (int flags);
叫用
mlockall()
,可以把當前行程之位址空間中的所有頁面鎖入實體記憶體。
flags
參數
(此參數可以被設定成下列兩值的逐位元 OR 邏輯運算)可用於控制此行為:
MCL_CURRENT
如果設定,此值會指示
mlockall()
把當前映射的所有頁面—堆疊、資料區段、被映 ...
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