0. Definition
The operating system (Operating System, OS) refers to the control and management of the hardware and software resources of the entire computer system, and reasonably organizes and schedules the work of the computer and the allocation of resources; to provide users and other software with a convenient interface and environment; it is The most basic system software in a computer system.
- The operating system is the manager of system resources
- Provide convenient and easy-to-use services to the upper layer
1. Features
The operating system (Operating System) is the first layer of software configured on the computer hardware.
1. Concurrency:
Concurrency refers to the occurrence of two or more events within the same time interval;
Parallelism:
Two or more events occur at the same time.
Concurrency looks like parallelism on a macro level
Note (important test points):
A single-core CPU can only execute one program at a time, and each program can only be executed concurrently
Multi-core CPU can execute multiple programs at the same time, and multiple programs can be executed in parallel
2. Sharing means that the resources in the system can be shared by multiple concurrently executing processes (threads) in the memory.
- Mutually exclusive sharing mode, although some resources in the system can be provided for use by multiple processes, only one process is allowed to access the resource within a period of time.
- Simultaneous access mode, some resources in the system allow multiple processes to access them "simultaneously" within a period of time.
3. Virtuality transforms a physical entity into several logical counterparts through a certain technology.
-
Time division multiplexing technology, virtual processor technology, virtual device technology
-
Space division multiplexing technology, virtual disk technology, virtual memory technology
4. Asynchronicity
2. Functions of the operating system
2.1 User and hardware interface
1. In the command mode, the user obtains the service of the operating system and controls the operation of the user program by inputting relevant commands;
-
Online command (interactive command)
-
Offline command (batch command);
2. System call mode, OS provides a set of system calls (functions), users can use the corresponding system calls in their own applications to communicate with the operating system and obtain its services;
3. Graphics and window mode, which allows users to communicate with the operating system and obtain its services through windows and icons on the screen.
2.2 Resource Manager
-
Processor management, for allocating and controlling processors;
-
Memory management, mainly responsible for memory allocation and recovery;
-
I/O device management, responsible for the allocation and manipulation of I/O devices;
-
File management, responsible for file access, sharing and protection.
2.3 Expansion machine
3. Development and classification of operating systems
Manual operation (no operating system)
Disadvantages:
(1) The user monopolizes the entire machine;
(2) CPU waits for manual operation.
Batch processing system (the operating system began to appear)
(1) single-channel batch processing system
Features: automaticity, sequence, single channel;
Disadvantage: During I/O operations, the CPU has nothing to do.
(2) Multi-channel batch processing system
Features: multi-channel, multi-task parallelism at the macro level, multi-task serialization at the micro level;
Pros: Improved system throughput due to improved utilization of CPU, memory, and I/O devices.
Problems to be solved:
processor management problems, memory management problems, I/O device management problems, file management problems and job management problems.
Disadvantages: no interactive ability .
Time-sharing system
Features: multiplex, independence, timeliness and interactivity ;
Cons: Cannot prioritize some urgent tasks
Real-time system
Features: multiplex, independence, timeliness , interactivity and reliability .
Microcomputer Operating System
Single-user single-task system, single-user multi-task system and multi-user multi-task system.
4. Operating mechanism
The programs written by our ordinary programmers are " applications"
Microsoft and Apple have a group of people responsible for implementing the operating system, and they write the " kernel program "
The "operating system kernel ", or " kernel " for short , is composed of many kernel programs.
The kernel is the most important and core part of the operating system, and it is also the part closest to the hardware.
4.1 Kernel state and user state
The CPU has two states, "kernel state" and "user state"
When in the kernel state , it means that the kernel program is running at this time , and privileged instructions can be executed at this time
When in user mode , it means that the application program is running at this time , and only non-privileged instructions can be executed at this time
Expansion: There is a register in the CPU called the program status word register (PSW), which has a binary bit, 1 means "kernel mode", 0 means "user mode"
Kernel mode → user mode: Execute a privileged instruction - modify the flag bit of PSW to "user mode", this action means that the operating system will actively give up the right to use the CPU
User mode→kernel mode: Triggered by "interrupt", the hardware automatically completes the metamorphosis process, triggering an interrupt signal means that the operating system will forcibly regain the right to use the CPU
4.2 Interruption and exception
"Interrupt" is the only way for the operating system kernel to regain CPU usage
Fundamentals of the Interrupt Mechanism
Different interrupt signals need to be handled by different interrupt handlers. When the CPU detects the interrupt signal, it will query the "interrupt vector table" according to the type of the interrupt signal, so as to find the storage location of the corresponding interrupt handler in the memory.
4.3 System calls
"System call" is an interface provided by the operating system to applications (programmers/programmers). It can be understood as a special function that can be called by applications. Applications can request services from the operating system kernel through system calls.
What functions use system calls?
Applications request services from the operating system through system calls. The various shared resources in the system are under the unified control of the operating system kernel, so all operations related to shared resources (such as storage allocation, I/O operations, file management, etc.) A service request is made and the operating system kernel completes it on its behalf. This can ensure the stability and security of the system and prevent users from performing illegal operations.
The process of the system call:
Pass the system call parameters → execute the trapped instruction (user mode) → execute the corresponding internal request kernel program to process the system call (core mode) → return to the application program
Notice:
1. Trapped instructions (trap instructions, access management instructions) are executed in the user mode, and an internal interrupt is triggered immediately after the execution of the trapped instructions, so that the CPU enters the core state 2. The system call request is issued in the user mode,
and the system call The corresponding processing is carried out in the core state
5. Operating System Architecture
operating system kernel
The kernel is the most basic and core part of the operating system.
Those programs that implement the functions of the operating system kernel are kernel programs.
Notice:
The operating system kernel needs to run in kernel mode
Non-kernel functions of the operating system run in user mode
exercise
On a uniprocessor system, parallelizable is (A)
l. Process and process
lI. Processors and Devices
III. Processor and Channel
IV. Equipment and Equipment
AI、Il和Ⅲ
B.l, ll and iv
C. I, III and V
D.lI, III and IV
Among the following options, the interface provided by the operating system to the application program is (A).
A system call
B. Interruption
C. Library functions
D. Primitive language
(2011 Unified Examination Questions) Among the following options, (A) is executed in user mode.
A command interpreter
B. Page fault handler
C.process scheduler
D. Clock interrupt handler
Eye state: also known as normal state or user state . When the machine is in the active state, the program can only execute non-privileged commands .
Management state: also called privileged state, system state or core state . The CPU can execute the full set of the finger joint system in the management state. Normally, an operating system runs in supervisor mode.
In a multi-channel batch processing system, there are only two jobs, PI and P2, and P2 arrives 5ms later than PI. Their calculation and I/O operation sequence is as follows:
PI: calculation 60ms, IO 80ms, calculation 20ms
P2: Calculate I20ms, I/O 40ms, calculate 40ms
If the scheduling and switching time are not considered, the minimum time required to complete the two jobs is (B)
A.240ms
B. 260ms
C. 340ms
D.360ms
Among the following options, the event that cannot happen in user mode is (C).
A system call
B.External interrupt
C. Process switching
D. Page fault
Both interrupt handling and subroutine calls need to be stacked to protect the scene. It is (B) that the interrupt processing must be saved and the subroutine call
does not need to save its content.
A. Program Counter
B. Program Status Word Register
C. General Data Register
D. General Address Register
After the computer is turned on, the operating system is finally loaded into (D).
A. BIOS
B. ROM
C. EPROM
D. RAM
ROM read-only memory, impossible to load into it.
BIOS is a type of software
RAM is random access memory
Among the following options, the operation that will cause the user process to switch from user mode to kernel mode is (B).
l. Integer division by zero
ll.sin() function call
Ⅲ. read system call
A only l, lI
B. Only l, Ⅲ
C.仅l、Ⅲ
D.I、ll和Ⅲ
The sin() function calls the call of an ordinary function