Computer Operating System Notes

Published 2026-08-11 18:26 5125 words 26 min read

Computer Operating System Study Notes

1. Introduction to Operating Systems

An operating system refers to the software that controls and manages the hardware and software resources of the entire computer system, rationally organizes and schedules the computer’s work and the allocation of resources, and provides users and other software with convenient interfaces and an environment. It is the most fundamental system software in a computer system (not hardware)

Bare machineOSApplicationUser
Refers to hardware: CPU, motherboarde.g., Windows, Linuxe.g., QQLiteral meaning

1.1 Characteristics

  • Concurrency: Two or more events occur within the same time interval; they are simultaneous at the macro level but interleaved at the micro level
  • Sharing: Resources in the system that can be used jointly by multiple concurrently executing processes in memory
    • Mutual-exclusion sharing: A resource allows only one process to access it during a specific period of time
      • For example: WeChat and QQ cannot access and use the camera at the same time
    • Simultaneous sharing: Within a period of time, multiple processes are allowed to access certain resources at the same time
      • For example: WeChat and QQ can access the photos in the album at the same time
  • Virtualization: A physical entity becomes several logical counterparts; the physical entity actually exists, while the logical counterparts are what the user perceives. The technology used to implement virtualization is also called virtual technology. Virtual memory technology uses multiprogramming techniques to time-share a single processor by having multiple programs execute concurrently.
  • Asynchronism: In a multiprogramming environment, multiple programs are allowed to execute concurrently, but due to limited resources, a process does not run straight through; it advances in a start-and-stop manner at an unpredictable speed. This is the asynchronism of processes.

1.2.1 Functions

As a manager, an operating system includes: processor management, memory management, file management, and device management.

  1. Processor management: In a multiprogramming environment, both allocation and execution are based on the process as the basic unit, so processor management can be summarized as process management, which includes: process control, process synchronization, process communication, deadlock handling, processor scheduling, etc.
  2. Memory management: It provides an environment that makes it convenient for users to use memory and improves memory utilization, including functions such as memory allocation and reclamation, address mapping, memory protection and sharing, and memory expansion.
  3. File management: Also called the file system, it includes: storage space management, directory management, file read/write management and protection, etc.
  4. Device management: It mainly fulfills users’ I/O requests, enables users to use various devices, and improves device utilization, including functions such as buffer management, device allocation, device handling, and virtual devices.

1.2.2 Interfaces

  • Command interface
      1. Online command interface: Also called the interactive command interface; an interface suitable for time-sharing or real-time systems
      1. Offline command interface: Also called the batch command interface; suitable for batch processing systems, it consists of a set of job control commands.
  • Program interface
    • Graphical interface: GUI (it is not part of the operating system; rather, the interfaces it calls are)

1.3 Development of Operating Systems

1.3.1 Single-channel Batch Processing System

  1. Characteristics: single-stream, exclusive, automatic, closed, sequential
  2. Drawback: system resources are not fully utilized

1.3.2 Multiprogrammed Batch Processing System

  1. Characteristics: multi-stream, shared, automatic, closed, unordered, schedulable
  2. Benefits: improves CPU utilization, increases memory and I/O device utilization, and increases system throughput
  3. Drawback: long average turnaround time and no interactive capability

1.3.3 Time-Sharing System

Concept: A system formed by connecting multiple terminals, each equipped with a display and keyboard, to a single host. The system allows multiple users to use the computer interactively through their own terminals at the same time, sharing the resources of the host.

  1. Characteristics: simultaneity, interactivity, independence, timeliness
  2. Drawback: it cannot guarantee timely processing within a specific time

1.3.4 Real-Time System

  1. Hard real-time: a certain action must absolutely be completed within the specified time
  2. Soft real-time: it may occasionally violate the time requirement, but it will not cause any permanent harm or damage
  3. Characteristics: timeliness and reliability

1.4 Operating Environment of the Operating System

1.4.1 User Mode and Kernel Mode

  1. The CPU executes two kinds of programs of different natures: one is the system kernel program, and the other is the application program
  2. The operating system distinguishes user mode and kernel mode, strictly separating the two kinds of programs: user-written programs run in user mode, while the operating system’s kernel programs run in kernel mode
    1. User mode: command interpreter
    2. Kernel mode: process scheduler, clock interrupt handler, page fault handler

[!lol] Fun Facts System calls are issued in user mode; the called program executes in kernel mode External interrupts occur in user mode, but their handling executes in kernel mode Page faults occur in user mode, and their handling executes in kernel mode The page fault handler executes in kernel mode

1.4.2 The Kernel

Concept: The kernel is the lowest-level software of a computer and an extension of the computer’s functions; it mostly includes four aspects

1.4.2.1 Clock

  1. Clock management: timers. Through clock management, the operating system needs to provide users with accurate time; through the management of clock interrupts, it can implement process switching.

1.4.2.2 Interrupts

  1. Interrupt mechanism: the original purpose of introducing it was to improve CPU utilization in a multiprogramming environment
    1. (For example, a data transfer request from an external device, a hardware fault, or a timer expiring, etc.) the CPU pauses the program currently being executed and instead executes a program that handles that special event (called the interrupt service routine)
    2. External interrupts (interrupts)
      1. They originate from outside the CPU and are related to the currently executing instruction
      2. Data structures controlled by the system and their handling: e.g., an interrupt signal is issued when an I/O operation completes
      3. Data structures controlled by the system and their handling: e.g., a user forcibly terminates a process
    3. Internal interrupts (exceptions)
      1. They originate from inside the CPU and are related to the currently executing instruction
      2. Voluntary interrupt — instruction interrupt
        1. e.g., using the supervisor call instruction (also called the trap instruction, the Trap instruction) during a system call
      3. Forced interrupt
        1. Mainly: hardware faults (e.g., page faults) or software interrupts (e.g., integer division by 0)
    4. The occurrence of an interrupt means the operating system needs to intervene
      1. Switching from user mode to kernel mode is implemented through interrupts, and interrupts are also the only way to do so
      2. Switching from kernel mode to user mode is done by executing some privileged instructions to set the flag bits of the Program Status Word (PSW) to user mode

1.4.2.3 Primitives

  1. Primitives: some low-level small common programs that can be called; each of them completes a specified operation and is indivisible.
    1. The lowest level
    2. Atomicity: Considering the system’s security and ease of management, the operation is completed in one go
    3. Short execution time
    4. Called relatively frequently
    5. The way to define a primitive is to disable interrupts, so that all other actions are completed indivisibly, and then enable interrupts again

1.4.2.4 Data Structures Controlled by the System and Their Handling

2. Description and Control of Processes

2.1 The Concept of a Process

2.1.1 Definition

  1. From different perspectives, a process can have different definitions; some classic ones are:
    1. A process is an execution of a program
    2. A process is the activity that occurs when a program and its data are executed sequentially on a processor
    3. A process is a program with independent functions that runs on a data set; it is an independent unit for the system to allocate resources and perform scheduling.

2.1.2 Composition

  1. A process is composed of the Process Control Block (PCB), a program segment, and a data segment
  2. The operating system manages processes through the PCB, so the PCB should contain all kinds of information the operating system needs to manage their execution, such as: process description information, process control and management information, a resource allocation list, and processor-related information. (For example, process state and priority information belong to the process description information)
    1. Program segment: the location where the program code is stored
    2. Data segment: the operation data used and generated when the program runs. For example, global variables, local variables, and constants defined by macros are stored in the data segment.
  3. A process can also be called: a process entity

2.1.3 Organization

  • Linked-list approach
    • PCBs are divided into multiple queues according to process state, and the operating system holds pointers to each queue
      • Ready queue
      • Running queue
      • Blocked queue
  • Index approach
    • Based on the different states of processes, several index tables are built, and the operating system holds pointers to each index table
      • Ready queue
      • Running queue
      • Blocked queue

2.1.4 Characteristics

  1. Dynamism: The most basic characteristic; a process is an execution process of a program and occurs dynamically
  2. Concurrency: Multiple process entities in memory; each process can execute concurrently
  3. Independence: The basic unit that can run independently, obtain resources independently, and be independently scheduled
  4. Asynchronism: Each process advances independently at an unpredictable speed; the operating system provides a process synchronization mechanism to solve the asynchronism problem
  5. Structuredness: Each process is equipped with a PCB; structurally, a process consists of a program segment, a data segment, and a PCB

[!lol] Interesting A process is dynamic A program is static and does not possess the characteristics of a process: dynamic, concurrent, independent, asynchronous, and structural.

  1. A program is reproducible (reproducibility: whether it runs from start to finish or starts and stops, it will obtain the same result)
  2. A program is closed (it runs in a closed environment and exclusively occupies the system’s resources; apart from its initial state, once it begins execution it is not affected by the outside world and can only change when it changes itself)

2.2 States and Transitions

2.2.1 Definition

Definition: The lifecycle of a process can be divided into a set of states, and these states characterize the entire process. Process states reflect the life state of a process.

2.2.2 The Five States

  1. New state: When creating a process, it needs to request a blank PCB, fill it with information for controlling and managing the process, and complete resource allocation. If the creation cannot be completed — for example, resources cannot be satisfied and it cannot be scheduled to run — the state the process is in at this time is called the new state.
  2. Running state: The process occupies the CPU’s resources and runs on the CPU
    1. With a single core, only one process is in the running state
    2. With dual cores, two processes can be in the running state
  3. Ready state: The process already has the conditions to run, but the CPU is busy and has not yet been allocated to it
  4. Blocked state: Also called the waiting state; it is waiting for something to happen and is temporarily unable to run
    1. When that event is completed, it returns to the ready state and waits for the CPU’s service
  5. Terminated state: Also called the withdrawn state; when a process ends, an error occurs, or the system is terminated, it enters the terminated state and can no longer execute
    1. The process of withdrawing is not completed in an instant; the operating system needs to reclaim the memory resources that were used at creation time

Transitions Between States

  • Running (running state) -> Ready (When entering the ready state, the process has already obtained all needed resources except the processor)
    1. The process occupies the CPU for too long; the CPU has limited resources to allocate
    2. It is preempted of CPU resources by preemptive priority
  • Ready -> Running
    1. The process’s time slice is used up, and it is scheduled to the ready queue; a process is allocated from the queue to the CPU
  • Running -> Blocked
    1. The executing process waits for some event and cannot execute, e.g., its turn for a resource has not come yet
  • Blocked -> Ready
    1. The event the process was waiting for has occurred
    2. Blocked -> Running is irreversible
    3. Ready -> Blocked is irreversible
      • For example: after a process’s disk read ends (while it is blocked), the OS changes the process’s state to ready instead of directly executing it

Applying for system resources through system calls, or applying to wait for a resource to be produced (for example, a resource has not been released and one waits for some running result), this is an I/O request.

2.3 Process Communication

2.3.1 Concept

Concept: it refers to the exchange of information between processes pv operations are the lowest-level communication; high-level communication refers to ways of transmitting large amounts of data with high efficiency.

2.3.2 Three Main Types of High-Level Communication

  1. Shared memory: a communication method based on shared data structures, e.g., producer-consumer. Next is the shared memory region-based communication method, which is a high-level communication method.
    • For example: Process A and Process B cannot directly access each other’s process space
    • So we need to use shared space to let the two processes access each other, but this method is mutually exclusive: when Process A accesses B’s process space, B cannot access A
    • For example: if the shared data structure can only hold an array of length 10, then each communication can only transmit one array of length 10, and if the data format is restricted, the transmission speed will be greatly reduced
    • Shared data structures are a somewhat low-level communication method
    • The shared memory region method, on the other hand, does not restrict length, format, location, etc., greatly improving transmission speed and transmission freedom; it is a high-level communication method
  2. Message passing: using formatted messages as the unit and transmitting messages with primitives; it is divided into direct communication and indirect communication. There are two kinds of primitives:
    • One is the send primitive
    • One is the receive primitive
    • A formatted message, for example: a sent message is divided into a message header and a message body
    • Direct communication attaches the message directly to the tail of a buffer queue, and then the process takes the messages from the head one by one using the receive primitive
    • Indirect communication, in contrast, first sends to an intermediate entity (also called a mailbox); when a message needs to be delivered, it is taken directly from the mailbox and identified by the message header to avoid transmission errors
  3. Pipe communication: a special way of passing information; it connects a reader process and a writer process to achieve file sharing between them, also called a “pipe” file
    • Simply put: a pipe is established between two processes, but a single pipe is half-duplex — it can send back and forth, but transmission can only occur in one direction at a time
    • Full duplex establishes another pipe, one for reading and one for writing, but their transfers are also mutually exclusive. For example: only after Process A finishes writing can Process B perform reading.

2.3 Threads

2.3.1 Introduction

  1. To simplify communication between processes and increase the degree of process concurrency with minimal overhead
  2. It is the smallest unit of execution in a process, an entity of the process, and the basic unit independently scheduled and dispatched by the system
  3. A thread does not own its own system resources; it only owns a little bit of resources essential for running, but it can share all the resources owned by the process with other threads belonging to the same process
  4. A thread can create and withdraw another thread, and multiple threads in the same process can execute concurrently

2.3.2 Concept

Concept: it is the basic unit of scheduling and dispatching

  1. A thread represents a control point of the process and can execute a series of instructions
  2. Decomposing a process into threads also allows effective use of multiprocessor and multicore computers

2.3.3 Comparison of Threads and Processes

2.3.3.1 Differences Between Processes and Threads
  1. Scheduling: threads are the basic unit of scheduling and allocation, while processes are the basic unit that owns resources
  2. Concurrency: processes can execute concurrently, and multiple threads of the same process can too
  3. Resource ownership: a process is an independent unit that owns resources; a thread does not own system resources but can access the resources belonging to its process
  4. System overhead: when creating or withdrawing a process, the system must allocate and reclaim resources for it, so the system overhead is clearly greater than the overhead of creating a thread
2.3.3.2 The Relationship Between Processes and Threads
  1. A thread belongs to only one process; a process has multiple threads, at least one
  2. Resources are allocated to processes, and threads of the same process can share all the resources of that process
  3. The processor is allocated to threads, i.e., what actually runs on the processor is the thread
  4. During execution, threads need to cooperate and synchronize. Threads of different processes need to use message communication to achieve synchronization. A thread is an execution unit within a process and also a schedulable entity within the process

3. Processor Scheduling

3.1 Basic Concepts of Processor Scheduling

  1. Basic criteria: different scheduling algorithms have different characteristics, and these characteristics must be considered when choosing a scheduling algorithm. To systematically compare the performance of processor scheduling algorithms, many evaluation criteria have been proposed.
    1. CPU utilization
      • The CPU is one of the most important and expensive resources of a computer, so it should be fully used by keeping the CPU “busy” to improve resource utilization
    2. System throughput
      • Represents the number of jobs the CPU completes per unit of time
    3. Turnaround time
      • Turnaround time refers to the time elapsed from when a job is submitted to when it is completed; it is the sum of the time the job waits, queues in the ready queue, runs on the processor, and performs input/output operations.
      1. Job turnaround time: turnaround time = job completion time - job submission time
      2. Average turnaround time: average turnaround time = the sum of the turnaround times of n jobs / n
      3. Average weighted turnaround time: the average of the weighted turnaround times of multiple jobs, equal to the sum of n weighted turnaround times / n
    4. Waiting time
      • Refers to the sum of the time a process is in the state of waiting for the processor; the longer the waiting time, the lower the user satisfaction rate
    5. Response time
      • Refers to the time from when a user submits a request to when the system first produces a response. In interactive systems, turnaround time cannot be the best evaluation criterion; response time is generally used as one of the main criteria for measuring scheduling algorithms.
  2. Three levels
    1. Job scheduling (high-level scheduling)
      • Its main task is to select one or more jobs from those in the backup state on external storage according to certain principles, allocate necessary resources such as memory and input/output devices to them, and create corresponding processes so that they gain the right to compete for the processor
      • This is the process of bringing jobs in
    2. Medium-level scheduling
      • Memory scheduling; its role is to improve memory utilization and system throughput
      • This is the process of swapping back, and it occurs more frequently than high-level scheduling
    3. Process scheduling (low-level scheduling)
      • Selects a process from the ready queue according to some method and policy and allocates the processor to it
  3. Process scheduling modes When a process is executing on the processor, if some important or urgent process needs to be handled — that is, a higher-priority process enters the ready state — then we need to consider how to allocate the processor
    1. Non-preemptive (non-preempting) scheduling
      • A process is running on the processor; even if a more urgent or higher-priority process enters the ready state, the processor is not given up immediately, but instead the current process is allowed to finish
    2. Preemptive (preempting) scheduling
      • A process is running on the processor; when a high-priority or urgent process enters the ready state, the processor is given up immediately to seize the current resources, even from the process currently executing

3.2 First-Come, First-Served Algorithm

  1. “First come first served” is: FCFS
  2. Scheduling is performed in the order in which jobs/processes arrive.
    • Drawback: it favors long jobs; the opposite for short jobs
    • Advantage: simple to implement
  3. Suitable for job scheduling and process scheduling

3.3 Shortest Job First

  1. “Short job first” is: SJF
  2. Priority is calculated based on the length of the job; the shorter the job, the higher its priority
  3. Suitable for job scheduling and process scheduling
    • Advantage: shortest average waiting time and average turnaround time
    • Drawback: the job’s running time must be known in advance; it is unfavorable to long jobs, starvation can occur, and the urgency of jobs is not considered

3.4 Priority Scheduling

4. Deadlock

5. Process Synchronization

6. Memory Management

7. File Management

8. Disk Organization and Management

9. I/O Device Management

If you enjoyed this, leave a comment~

... Page views
© 2021 - 2026 Vullfin @VV
Powered by theme astro-koharu · Inspired by Shoka