Linux編程接口里的插圖

[TOC]

Some useful commands

$ ldd /bin/ls | grep libc
        libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb75e6000)
$ /lib/i386-linux-gnu/libc.so.6

Setps in the execution of a system call

圖片.png

Relationship between file descriptors, open file descriptions, and i-nodes

圖片.png

Typical memory layout of a process on Linux/x86-32

圖片.png

Overview of virtual memory

圖片.png

Heap containing allocated blocks and a free list

圖片.png

Selected files in each /proc/PID directory

圖片.png

Summary of I/O buffering

圖片.png

Structure of the file blocks for a file in an ext2 file system

圖片.png

I-node flags

圖片.png

From the shell, i-node flags can be set and viewed using the chattr and lsattr commands.

ACL (Access Control List)

An ACL is a series of ACL entries, each of which defines the file permissions for an individual user or group of users:

圖片.png

Relationship between i-node and directory structures

圖片.png

Representation of hard and symbolic links

圖片.png

Linux signals

圖片.png

Signal delivery and handler execution

圖片.png

Run for a few seconds elapsed time

for (startTime = time(NULL); time(NULL) < startTime + 4; )
    continue;       /* Run for a few seconds elapsed time */

Overview of the use of fork(), exit(), wait() and execve()

圖片.png

Value returned in the status argument of wait() and waitpid()

圖片.png
void handler(int sig)
{
    /* Perform cleanup steps */
    
    signal(sig, SIG_DFL);   /* Disestablish handler */
    raise(sig);             /* Raise signal again */
}

The argument list supplied to an execed script

圖片.png

execution of system("sleep 20")

圖片.png

As an efficiency measure, when the string given to the -c option is a simple command (as opposed to a pipeline or a sequence), some shells (including bash) directly exec the command, rather than forking a child shell. For shells that perform such an optimization, Figure 27-2 is not strictly accurate, since there will be only two processes (the calling process and sleep).

Four threads executing in a process (Linux/x86-32)

圖片.png

We have simplified things somewhat in Figure 29-1. In particular, the location of the per-thread stacks may be intermingled with shared libraries and shared memory regions, depending on the order in which threads are created, shared libraries loaded, and shared memory regions attached. Further more, the location of the per-thread stacks can vary depending on the Linux distribution.

/* When using threads, errno is a per-thread value.  */
#define errno (*__errno_location ())

Each reference to errno in a threaded program carries the overhead of a function call.

Thread-specific data (TSD) provides per-thread storage for a function

圖片.png

Relationships between process groups, sessions, and the controlling terminal

圖片.png

Job-control states

圖片.png

Resources values for getrlimit() and setrlimit()

圖片.png

Overview of system logging

圖片.png

Creating a shared library and linking a program against it

圖片.png

Execution of a program that loads a shared library

圖片.png

real name, soname, linker name

圖片.png

Finding Shared Libraries at Run Time

圖片.png

A taxonomy of UNIX facilities

圖片.png

Identifiers and handles for various types of IPC facilities

圖片.png

Setting up a pipe to transfer data from parent to a child

圖片.png

popen()

圖片.png

Using a FIFO and tee(1) to create a dual pipeline

$ mkfifo myfifo
$ wc -l < myfifo &
$ ls -l | tee myfifo | sort -k5n
圖片.png

Separating messages in a byte stream

圖片.png

Overview of memory-mapped file

圖片.png

Two processes with a shared mapping of the same region of a file

圖片.png

We simplify things in this diagram by omitting to show that the mapped pages are typically not contiguous in physical memory.

Memory mapping whose length is not a multiple of the system page size

圖片.png

Memory mapping extending beyond end of mapped file

圖片.png

Summary of programming interfaces for POSIX IPC objects

圖片.png

Socket domains

圖片.png

Socket types and their properties

圖片.png

Overview of system calls used with stream sockets

圖片.png

A pending socket connection

圖片.png

Overview of system calls used with datagram sockets

圖片.png

Generic address structure, struct sockaddr

struct sockaddr {
   sa_family_t sa_family;
   char        sa_data[14];
}

/* UNIX domain */

#define UNIX_PATH_MAX    108

struct sockaddr_un {
   sa_family_t sun_family;               /* AF_UNIX */
   char        sun_path[UNIX_PATH_MAX];  /* pathname */
};

/* IPv4 domain */

struct sockaddr_in {
   sa_family_t    sin_family; /* address family: AF_INET */
   in_port_t      sin_port;   /* port in network byte order */
   struct in_addr sin_addr;   /* internet address */
   /* pad to size of 'struct sockaddr' */
   unsigned char __pad[sizeof (struct sockaddr) -
                  sizeof (sa_family_t) -
                  sizeof (in_port_t) -
                  sizeof(struct in_addr)];
};

/* Internet address. */
struct in_addr {
   uint32_t       s_addr;     /* address in network byte order */
};

/* IPv6 domain */

struct sockaddr_in6 {
   sa_family_t     sin6_family;   /* AF_INET6 */
   in_port_t       sin6_port;     /* port number */
   uint32_t        sin6_flowinfo; /* IPv6 flow information */
   struct in6_addr sin6_addr;     /* IPv6 address */
   uint32_t        sin6_scope_id; /* Scope ID (new in 2.4) */
};

/* IPv6 address */
struct in6_addr
  {
    union
      {
    uint8_t __u6_addr8[16];
#ifdef __USE_MISC
    uint16_t __u6_addr16[8];
    uint32_t __u6_addr32[4];
#endif
      } __in6_u;
#define s6_addr         __in6_u.__u6_addr8
#ifdef __USE_MISC
# define s6_addr16      __in6_u.__u6_addr16
# define s6_addr32      __in6_u.__u6_addr32
#endif
  };

#define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }
#define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }

TCP/IP protocol layers

圖片.png

Format of an IPv4-mapped IPv6 address

圖片.png

Connected TCP sockets

圖片.png

Transferring the contents of a file to a socket

圖片.png

Format of a TCP segment

圖片.png

TCP state transition diagram

圖片.png

Three-way handshake for TCP connection establishment

圖片.png

Thye connection termination

圖片.png

Input and output queues for a terminal device

圖片.png

Terminal Special characters

圖片.png

select() and poll indication for sockets

圖片.png

Times taken by poll(), select() and epoll for 100,000 monitoring operations

圖片.png

Two programs communicating via a pseudoterminal

圖片.png

How ssh uses a pseudoterminal

圖片.png

Figure 64-3 shows a specific example: the use of pseudoterminal by ssh, an application that allows a user to securely run a login session on a remote system connected via a network. On the remote host, the driver program for the pseudoterminal master is the ssh server (sshd), and the terminal-oriented program connected to the pseudoterminal slave is the login shell. The ssh server is the glue that connects the pseudoterminal via a socket to the ssh client. Once all of the details of logging in have been completed, the primary purpose of the ssh server and client is to relay characters in either direction between the user's terminal on the local host and the shell on the remote host.

圖片.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末尔觉,一起剝皮案震驚了整個(gè)濱河市兰珍,隨后出現(xiàn)的幾起案子掸读,更是在濱河造成了極大的恐慌抖单,老刑警劉巖,帶你破解...
    沈念sama閱讀 206,602評(píng)論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件闯袒,死亡現(xiàn)場(chǎng)離奇詭異锋恬,居然都是意外死亡桶蝎,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,442評(píng)論 2 382
  • 文/潘曉璐 我一進(jìn)店門(mén)乏奥,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)恨诱,“玉大人,你說(shuō)我怎么就攤上這事兢仰〖敛辏” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 152,878評(píng)論 0 344
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我,道長(zhǎng),這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 55,306評(píng)論 1 279
  • 正文 為了忘掉前任各淀,我火速辦了婚禮临谱,結(jié)果婚禮上抄课,老公的妹妹穿的比我還像新娘。我一直安慰自己沦童,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,330評(píng)論 5 373
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著相速,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上伏社,一...
    開(kāi)封第一講書(shū)人閱讀 49,071評(píng)論 1 285
  • 那天抠刺,我揣著相機(jī)與錄音,去河邊找鬼摘昌。 笑死速妖,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的聪黎。 我是一名探鬼主播罕容,決...
    沈念sama閱讀 38,382評(píng)論 3 400
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼稿饰!你這毒婦竟也來(lái)了锦秒?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 37,006評(píng)論 0 259
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤喉镰,失蹤者是張志新(化名)和其女友劉穎旅择,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體侣姆,經(jīng)...
    沈念sama閱讀 43,512評(píng)論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡生真,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 35,965評(píng)論 2 325
  • 正文 我和宋清朗相戀三年沉噩,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片柱蟀。...
    茶點(diǎn)故事閱讀 38,094評(píng)論 1 333
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡川蒙,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出长已,到底是詐尸還是另有隱情畜眨,我是刑警寧澤,帶...
    沈念sama閱讀 33,732評(píng)論 4 323
  • 正文 年R本政府宣布术瓮,位于F島的核電站康聂,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏斤斧。R本人自食惡果不足惜早抠,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,283評(píng)論 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望撬讽。 院中可真熱鬧蕊连,春花似錦、人聲如沸游昼。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 30,286評(píng)論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)烘豌。三九已至载庭,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間廊佩,已是汗流浹背囚聚。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 31,512評(píng)論 1 262
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留标锄,地道東北人顽铸。 一個(gè)月前我還...
    沈念sama閱讀 45,536評(píng)論 2 354
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像料皇,于是被迫代替她去往敵國(guó)和親谓松。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,828評(píng)論 2 345

推薦閱讀更多精彩內(nèi)容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,294評(píng)論 0 10
  • “跟你說(shuō)個(gè)好消息,我買(mǎi)的股票從12塊錢(qián)漲到20塊錢(qián)了逊脯!” “早知道今天北京的房?jī)r(jià)如此之高我在2004年剛到北京那會(huì)...
    Fei向宇宙閱讀 158評(píng)論 0 0
  • 由于這幾天需要學(xué)習(xí)PHP优质,關(guān)于配置MySQL,Apache等等一系列的東西男窟。在網(wǎng)上找的很多教程都或多或少的存在一些...
    SimpLe丶yo閱讀 2,392評(píng)論 7 6
  • 1盆赤、office和基本軟件(云盤(pán)贾富,wiz筆記歉眷,印象筆記......)的熟練應(yīng)用牺六。 office不是只是叫你word...
    成長(zhǎng)MVP閱讀 1,023評(píng)論 0 3