您的位置:首页 > 运维架构 > Linux

The Linux Programming Interface 02 Fundamental Concepts 基本概念

2017-02-27 16:53 483 查看
Fundamental Concepts

系统中基本概念的介绍

(01) Although it is possible to run programs on a computer without a kernel, the presence of a kernel greatly simplifies the writing and use of other programs, and increases the power and flexibility available to programmers.

Linux可执行内核在/boot/vmlinuz 下面。

(02) kernel的任务

    1. Process scheduling

    2. Memory management

    3. Provision of a file system

    4. Creation and termination of process 创建和终止进程

    The kernel can load a new program into memory, providing it with the resources (e.g., CPU, memory, and access to files) that it needs in order to run. Such an instance of a running program is termed a process. Once a process has completed execution,
the kernel ensures that the resources it uses are freed for subsequent reuse by later programs.

    5. Access to devices

    6. Networking

    7. Provision of a system call application programming interface(API)

(03) 内核描述

By contrast, a running system has one kernel that knows and controls everything. The kernel facilities the running of all processes on the system. The kernel decides which process will next obtain access to the CPU, when it will do so, and for how long.
The kernel maintains data structures containing information about all running processes and updates these structures as processes are created, change state, and terminate. The kernel also maintains data structures all of the low-level data structures that
enable the filenames used by programs to be translated into physical location on the disk. The kernel also maintains data structures that map the virtual memory of each process into the physical memory of the computer and the swap area(s) on disk. All communication
between processes is done via mechanisms provided by the kernel. In response to requests from processes, the kernel creates new processes and terminates existing processes. Lastly, the kernel (in particular, device drivers) performs all direct communication
with input and output devices, transferring information to and from user processes as required.

(04) 目录

A directory is a special file whose contents take the form of a table of filenames coupled with references to the corresponding files. This filename-plus-reference association is called a link.

(05) 软链接

和windows下的快捷方式的那个文件有很接近的意味。

硬链接实际上是为文件建一个别名,链接文件和原文件实际上是同一个文件。可以通过ls -i来查看一下,这两个文件的inode号是同一个,说明它们是同一个文件;而软链接建立的是一个指向,即链接文件内的内容是指向原文件的指针,它们是两个文件。

(06)相对路径

A relative pathname specifies the location of a file relative to a process's current working directory, and is distinguished from an absolute pathname by the absence of an initial slash.

(07)文件权限,用户被分为三种类型

For the purpose of accessing a file, the system divides users into three categories: the owner of the file (sometimes termed the user of the file), users who are members of group matching the file's group ID (group),
and the rest of the world(other).

(08) 统一的I/O接口

The kernel translates the application's I/O requests into appropriate file-system or device-driver operations that perform I/O on the target file or device.

(09) 文件描述符

A file descriptor is typically obtained by a call to open(), which takes a pathname argument specifying a file upon which I/O is to be performed.

To perform file I/O, C programs typically employ I/O functions contained in the standard C library. This set of functions, referred to as the stdio library, includes fopen(), fclose(), scanf(), printf(), fgets(), fputs(),
and so on. The stdio functions are layered on top of the I/O system calls (open(), close(), read(), write(), and so on.

(10) 进程

When a program is executed, the kernel loads the code of program into virtual memory, allocates space for program variables, and sets up kernel bookkeeping data structures to record various information (such as process
ID, termination status, user IDs, and group IDs) about the process.

A process can terminate in one of two ways: by requesting its own termination using the _exit() system call (or the related exit() library function), or by being killed the delivery of a signal. In either case, the process
yields a termination status, a small nonnegative integer value that is available for inspection by the parent process using the wait() system call.

(11) 映射,主要是mmap()函数

(12) 动态库和静态库

If a program is linked against a shared library, then, instead of copying object modules from the library into the executable, the linker just writes a record into the executable to indicate that at run time the executable
needs to use that shared library. When the executable is loaded into memory at run time, a program called the dynamic linker ensures that the shared libraries required by the executable are found and loaded into memory.

(13)进程间通信及同步

signals, pipes, sockets, file locking, massage queues, semaphores, shared memory.

(14) 信号

For example, the kernel may send a signal to a process when one of the following occurs:

the user typed the interrupt character (usually Control-C) on the keyboard;

one of the process's children has terminated;

a timer (alarm clock) set by the process has expired; or

the process attempted to access an invalid memory address.

(15) 线程

One way of envisaging(想象) threads is as a set of processes that share the same virtual memory, as well as a range of other attributes. Each thread is executing the same program code and shares the same data area and heap.
However, each thread has it own stack containing local variables and function call linkage information.

(16) Sessions, Controlling Terminals, and Controlling Processes

这部分还没有理解。

A session is a collection of process groups.

Sessions are used mainly by job-control shells.

(17) 伪终端,不理解。

时间分为系统时间和进程时间。

(18) Client - Server 架构

A client-server application is one that is broken into two component processes:

a client, which asks the server to carry out some service by sending it a request message; and

a server, which examines the client's request, performs appropriate actions, and then sends a response message back to the client.

(19) proc 文件系统

The /proc file system is a virtual file system that provides an interface to kernel data structures in a form that looks like files and directories on a file system. This provides an easy mechanism for viewing and changing various system attributes.

(20)总结

In this chapter, we surveyed a range of fundamental concepts related to Linux system programming. An understanding of these concepts should provide readers with limited experience on Linux or UNIX with enough background to begin learning system programming.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: