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

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

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

Overview of virtual memory

Heap containing allocated blocks and a free list

Selected files in each /proc/PID directory

Summary of I/O buffering

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

I-node flags

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:

Relationship between i-node and directory structures

Representation of hard and symbolic links

Linux signals

Signal delivery and handler execution

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()

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

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

execution of system("sleep 20")

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)

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

Relationships between process groups, sessions, and the controlling terminal

Job-control states

Resources values for getrlimit() and setrlimit()

Overview of system logging

Creating a shared library and linking a program against it

Execution of a program that loads a shared library

real name, soname, linker name

Finding Shared Libraries at Run Time

A taxonomy of UNIX facilities

Identifiers and handles for various types of IPC facilities

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

popen()

Using a FIFO and tee(1) to create a dual pipeline
$ mkfifo myfifo
$ wc -l < myfifo &
$ ls -l | tee myfifo | sort -k5n

Separating messages in a byte stream

Overview of memory-mapped file

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

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

Memory mapping extending beyond end of mapped file

Summary of programming interfaces for POSIX IPC objects

Socket domains

Socket types and their properties

Overview of system calls used with stream sockets

A pending socket connection

Overview of system calls used with datagram sockets

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

Format of an IPv4-mapped IPv6 address

Connected TCP sockets

Transferring the contents of a file to a socket

Format of a TCP segment

TCP state transition diagram

Three-way handshake for TCP connection establishment

Thye connection termination

Input and output queues for a terminal device

Terminal Special characters

select() and poll indication for sockets

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

Two programs communicating via a pseudoterminal

How ssh uses a pseudoterminal

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.
