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

Linux编程接口里的插图_第1张图片
图片.png

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

Linux编程接口里的插图_第2张图片
图片.png

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

Linux编程接口里的插图_第3张图片
图片.png

Overview of virtual memory

Linux编程接口里的插图_第4张图片
图片.png

Heap containing allocated blocks and a free list

Linux编程接口里的插图_第5张图片
图片.png

Selected files in each /proc/PID directory

Linux编程接口里的插图_第6张图片
图片.png

Summary of I/O buffering

Linux编程接口里的插图_第7张图片
图片.png

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

Linux编程接口里的插图_第8张图片
图片.png

I-node flags

Linux编程接口里的插图_第9张图片
图片.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:

Linux编程接口里的插图_第10张图片
图片.png

Relationship between i-node and directory structures

Linux编程接口里的插图_第11张图片
图片.png

Representation of hard and symbolic links

Linux编程接口里的插图_第12张图片
图片.png

Linux signals

Linux编程接口里的插图_第13张图片
图片.png

Signal delivery and handler execution

Linux编程接口里的插图_第14张图片
图片.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()

Linux编程接口里的插图_第15张图片
图片.png

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

Linux编程接口里的插图_第16张图片
图片.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

Linux编程接口里的插图_第17张图片
图片.png

execution of system("sleep 20")

Linux编程接口里的插图_第18张图片
图片.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)

Linux编程接口里的插图_第19张图片
图片.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

Linux编程接口里的插图_第20张图片
图片.png

Relationships between process groups, sessions, and the controlling terminal

Linux编程接口里的插图_第21张图片
图片.png

Job-control states

Linux编程接口里的插图_第22张图片
图片.png

Resources values for getrlimit() and setrlimit()

Linux编程接口里的插图_第23张图片
图片.png

Overview of system logging

Linux编程接口里的插图_第24张图片
图片.png

Creating a shared library and linking a program against it

Linux编程接口里的插图_第25张图片
图片.png

Execution of a program that loads a shared library

Linux编程接口里的插图_第26张图片
图片.png

real name, soname, linker name

Linux编程接口里的插图_第27张图片
图片.png

Finding Shared Libraries at Run Time

Linux编程接口里的插图_第28张图片
图片.png

A taxonomy of UNIX facilities

Linux编程接口里的插图_第29张图片
图片.png

Identifiers and handles for various types of IPC facilities

Linux编程接口里的插图_第30张图片
图片.png

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

Linux编程接口里的插图_第31张图片
图片.png

popen()

Linux编程接口里的插图_第32张图片
图片.png

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

$ mkfifo myfifo
$ wc -l < myfifo &
$ ls -l | tee myfifo | sort -k5n
Linux编程接口里的插图_第33张图片
图片.png

Separating messages in a byte stream

Linux编程接口里的插图_第34张图片
图片.png

Overview of memory-mapped file

Linux编程接口里的插图_第35张图片
图片.png

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

Linux编程接口里的插图_第36张图片
图片.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

Linux编程接口里的插图_第37张图片
图片.png

Memory mapping extending beyond end of mapped file

Linux编程接口里的插图_第38张图片
图片.png

Summary of programming interfaces for POSIX IPC objects

Linux编程接口里的插图_第39张图片
图片.png

Socket domains

Linux编程接口里的插图_第40张图片
图片.png

Socket types and their properties

Linux编程接口里的插图_第41张图片
图片.png

Overview of system calls used with stream sockets

Linux编程接口里的插图_第42张图片
图片.png

A pending socket connection

Linux编程接口里的插图_第43张图片
图片.png

Overview of system calls used with datagram sockets

Linux编程接口里的插图_第44张图片
图片.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

Linux编程接口里的插图_第45张图片
图片.png

Format of an IPv4-mapped IPv6 address

Linux编程接口里的插图_第46张图片
图片.png

Connected TCP sockets

Linux编程接口里的插图_第47张图片
图片.png

Transferring the contents of a file to a socket

Linux编程接口里的插图_第48张图片
图片.png

Format of a TCP segment

Linux编程接口里的插图_第49张图片
图片.png

TCP state transition diagram

Linux编程接口里的插图_第50张图片
图片.png

Three-way handshake for TCP connection establishment

Linux编程接口里的插图_第51张图片
图片.png

Thye connection termination

Linux编程接口里的插图_第52张图片
图片.png

Input and output queues for a terminal device

Linux编程接口里的插图_第53张图片
图片.png

Terminal Special characters

Linux编程接口里的插图_第54张图片
图片.png

select() and poll indication for sockets

Linux编程接口里的插图_第55张图片
图片.png

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

Linux编程接口里的插图_第56张图片
图片.png

Two programs communicating via a pseudoterminal

Linux编程接口里的插图_第57张图片
图片.png

How ssh uses a pseudoterminal

Linux编程接口里的插图_第58张图片
图片.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.

Linux编程接口里的插图_第59张图片
图片.png

你可能感兴趣的:(Linux编程接口里的插图)