美文网首页我爱编程
Linux编程接口里的插图

Linux编程接口里的插图

作者: 默念2009 | 来源:发表于2018-04-16 09:52 被阅读0次

[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

相关文章

网友评论

    本文标题:Linux编程接口里的插图

    本文链接:https://www.haomeiwen.com/subject/fjilcftx.html