The Linux Programming Interface 02 Fundamental Concepts 基本概念__Linux

來源:互聯網
上載者:User

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.


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.