《Understanding the Linux kernel》学习笔记 Chapter 1: Introduction

本文介绍了Unix类操作系统的几个核心概念,包括基本操作系统原理、多用户系统的特点、进程管理、内核架构等,并深入探讨了文件系统的工作机制,如文件类型、链接方式以及文件权限管理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Basic Operating System Concepts

The operating system must fulfill two main objectives:

  • Interact with the hardware components, serving all low-level programmable elements included in the hardware platform.
  • Provide an execution environment to the application that run on the computer system (the so-called user programs).
A  Unix-like operating system hides all low-level details concerning the physical organization of the computer from applications run by the user.

Multiuser Systems
Multiuser operating systems must include several features:
  • An authentication mechanism for verifying the user's identity
  • A protection mechanism against buggy user programs that could block other application running in the system
  • A protection mechanism against malicious user programs that could interfere with or spy on the activity of other users
  • An accounting mechanism that limits the amount of resource units assigned to each user

Users and Groups
All users are identified by a unique number called the User ID, or UID.
To selectively share material with other users, each user is a member of one or more user groups, which are identified by a unique number called a user group ID.

Processes
A process can be defined as "an instance of a program in execution" or as the "execution context" of a running program.
Systems that allow concurrent active processes are said to be multiprogramming or multiprocessing.
An operating system component called the scheduler chooses the process that can progress.
Unix is a multiprocessing operating system with preemptable processes.
Unix-like operating systems adopt a process/kernel model.

Kernel Architecture
A module is an object file whose code can be linked to (and unlinked from) the kernel at runtime. The object code usually consists of a set of functions that implements a filesystem, a device, or other features at the kernel's upper layer.

An Overview of the Unix Filesystem

Files

A Unix file is an information container structured as a sequence of bytes; the kernel does not interpret the contents of a file.

Unix associates a current working directory with each process; it belongs to the process execution context, and it identifies the directory currently used by the process.


Hard and Soft Links

A filename included in a directory is called a file hard link, or more simply, a link.

Hard links have two limitations:

  • It is not possible to create hard links for directories.
  • Links can be created only among files included in the same filesystem.

To overcome these limitations, soft links (also called symbolic links) were introduced a long time ago. Symbolic links are short files that contain an arbitrary pathname of another file. The pathname may refer to any file or directory located in any filesystem; it may even refer to a nonexistent file.

File Types

Unix files may have one of the following types:

  • Regular file
  • Directory
  • Symbolic link
  • Block-oriented device file
  • Character-oriented device file
  • Pipe and named pip (also called FIFO)
  • Socket

File Descriptor and Inode

All information needed by the filesystem to handle a file is included in a data structure called an inode. Each file has its own inode, which the filesystem uses to identify the file.


Access Right and File Mode

The potential users of a file fall into three classes:

  • The user who is the owner of the file
  • The users who belong to the same group as the file, not including the owner
  • All remaining users (others)
There are three types of access rights -- read, write, and excute -- for each of those three classes.

File-Handling System Calls


An Overview of Unix Kernels

The Process/Kernel Model

The process/kernel model assumes that processes that require a kernel service use specific programming constructs called system calls.

Unix kernels do much more than handle system calls; in fact, kernel routines can be activated in several ways:

  • A process invokes a system call.
  • The CPU executing the process signals an exception, which is an unusual condition such as an invalid instruction. The kernel handles the exception on behalf of the process that caused it.
  • A peripheral device issues an interrupt signal to the CPU to notify it of an event such as a request for attention, a status change, or the completion of an I/O operation. Each interrupt signal is dealt by a kernel program called an interrupt handler.
  • A kernel thread is excuted.

Process Implementation

When the kernel stops the execution of a process, it saves the current contents of several processor registers in the process descriptor.

When the kernel decides to resume executing a process, it uses the proper process descriptor fields to load the CPU registers.

When a process is not executing on the CPU, it is waiting for some event.


Reentrant Kernels

All Unix kernels are reentrant. This means that several processes may be executing in Kernel Mode at the same time.

When one of the following events occurs, the CPU interleaves the kernel control paths:

  • A process executing in User Mode invokes a system call, and the corresponding kernel control path verifies that the request cannot be satisfied immediately; it then invokes the scheduler to select a new process to run.
  • The CPU detects an exception -- for example, access to a page not present in RAM -- while running a kernel control path.
  • A hardware interrupt occurs while the CPU is running a kernel control path with the interrupts enabled.
  • An interrupt occurs while the CPU is running with kernel preemption enabled, and a higher priority process is runnable.

Process Address Space

Each process runs in its private address space.


Synchronization and Critical Regions

Kernel preemption disabling

Interrupt disabling

Semaphores

Spin locks

Avoiding deadlocks


Signals and Interprocess Communication

Unix signals provide a mechanism for notifying processes of system events.

AT&T's Unix System V introduced other kinds of interprocess communication among processes in User Mode, which have adopted by many Unix kernels: semaphores, message queues, and shared memory. They are collectively known as System V IPC.


Process Management

Zombie processes

Process groups and login sessions


Memory Management

Virtual memory

Virtual memory acts as a logical layer between the application memory requests and the hardware Memory Management Unit (MMU).


Random access memory usage

Kernel Memory Allocator

Process virtual address space handling

Caching


Device Drivers

The kernel interacts with I/O devices by means of device drivers. Device drivers are included in the kernel and consist of data structures and functions that control one or more devices. Each driver interacts with the remaining part of the kernel (even with other drivers) through a specific interface.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值