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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 217,826评论 6 506
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,968评论 3 395
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 164,234评论 0 354
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,562评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,611评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,482评论 1 302
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,271评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,166评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,608评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,814评论 3 336
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,926评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,644评论 5 346
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,249评论 3 329
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,866评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,991评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,063评论 3 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,871评论 2 354

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,331评论 0 10
  • “跟你说个好消息,我买的股票从12块钱涨到20块钱了!” “早知道今天北京的房价如此之高我在2004年刚到北京那会...
    Fei向宇宙阅读 161评论 0 0
  • 由于这几天需要学习PHP,关于配置MySQL,Apache等等一系列的东西。在网上找的很多教程都或多或少的存在一些...
    SimpLe丶yo阅读 2,398评论 7 6
  • 1、office和基本软件(云盘,wiz笔记,印象笔记......)的熟练应用。 office不是只是叫你word...
    成长MVP阅读 1,036评论 0 3