The Linux Programming Interface 02 Fundamental Concepts 基本概念

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.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
A Linux and UNIX® System Programming Handbook Chapter 1: History and Standards Chapter 2: Fundamental Concepts Chapter 3: System Programming Concepts Chapter 4: File I/O: The Universal I/O Model Chapter 5: File I/O: Further Details Chapter 6: Processes Chapter 7: Memory Allocation Chapter 8: Users and Groups Chapter 9: Process Credentials Chapter 10: Time Chapter 11: System Limits and Options Chapter 12: System and Process Information Chapter 13: File I/O Buffering Chapter 14: File Systems Chapter 15: File Attributes Chapter 16: Extended Attributes Chapter 17: Access Control Lists Chapter 18: Directories and Links Chapter 19: Monitoring File Events Chapter 20: Signals: Fundamental Concepts Chapter 21: Signals: Signal Handlers Chapter 22: Signals: Advanced Features Chapter 23: Timers and Sleeping Chapter 24: Process Creation Chapter 25: Process Termination Chapter 26: Monitoring Child Processes Chapter 27: Program Execution Chapter 28: Process Creation and Program Execution in More Detail Chapter 29: Threads: Introduction Chapter 30: Threads: Thread Synchronization Chapter 31: Threads: Thread Safety and Per-Thread Storage Chapter 32: Threads: Thread Cancellation Chapter 33: Threads: Further Details Chapter 34: Process Groups, Sessions, and Job Control Chapter 35: Process Priorities and Scheduling Chapter 36: Process Resources Chapter 37: Daemons Chapter 38: Writing Secure Privileged Programs Chapter 39: Capabilities Chapter 40: Login Accounting Chapter 41: Fundamentals of Shared Libraries Chapter 42: Advanced Features of Shared Libraries Chapter 43: Interprocess Communication Overview Chapter 44: Pipes and FIFOs Chapter 45: Introduction to System V IPC Chapter 46: System V Message Queues Chapter 47: System V Semaphores Chapter 48: System V Shared Memory Chapter 49: Memory Mappings Chapter 50: Virtual Memory Operations Chapter 51: Introduction to POSIX IPC Chapter 52: POSIX Message Queues Chapter 53: POSIX Semaphores Chapter 54: POSIX Shared Memory Chapter 55: File Locking Chapter 56: Sockets: Introduction Chapter 57: Sockets: UNIX Domain Chapter 58: Sockets: Fundamentals of TCP/IP Networks Chapter 59: Sockets: Internet Domains Chapter 60: Sockets: Server Design Chapter 61: Sockets: Advanced Topics Chapter 62: Terminals Chapter 63: Alternative I/O Models Chapter 64: Pseudoterminals

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值