Operating System (1): Overview of Operating System [Introduction to operating system can not be missed...]

Study hard and make progress every day

This article has been included in my Github repository DayDayUP : github.com/RobodLee/DayDayUP, welcome to Star

Preface

I haven't studied the operating system systematically before, and I feel that I have a messy understanding of certain concepts in my usual learning process, such as interrupts, memory, processes, and threads. So I plan to learn about the operating system systematically. At the beginning, I watched teacher Li Zhijun from Harbin Institute of Technology at station B. But I started to analyze the boot process from the assembly code. Although it was very good, I might be too stupid to understand. So I watched Soochow University's "Operating System" on the Chinese University MOOC .

In other words, this is also a national boutique. Although it is not very good, it is quite easy to accept. The book I read is "Operating System Concept Seventh Edition"

This series of articles serves as my notes for learning operating systems, and I hope to help those who want to learn and are learning operating systems. Not much to force, the official content will begin below.

What is operating system

This is a logical diagram of the components of a computer system. It can be seen from the diagram that users have to use the operating system if they want software to run on computer hardware. The operating system is the lowest level software of the computer, and it is the basic support environment for the running of applications, and it is indispensable. But the operating system is not necessarily necessary. For example, some small computers like single-chip microcomputers can run programs even without an operating system.

What is the meaning of the operating system? I think it is " convenient " for ordinary users and developers . printf("hello world!");Everyone has written, why can such a line of code output a sentence on the screen? It is because after running this line of code, it calls the interface of the operating system, and then the operating system controls the underlying hardware for related operations. For us, these are nonsensical, just writing a line of code. .

So my understanding of the operating system is: the operating system is the housekeeper, and the computer hardware is the house, and the user is the owner of the house. For example, when we want to eat, we tell the butler that it is time to cook, and then the butler will dispatch and arrange for people to buy and cook, and we only need to wait for the food to be served. If there is no butler, then these things have to be done by yourself. So with the operating system, we can use the computer comfortably and efficiently.

Multi-program design and time sharing

The current operating system is not so great at the beginning, but has gone through multiple stages of evolution.

No operating system (manual operation)

The earliest computers did not have an operating system. For example, ENIAC manually operated cables to perform tasks, which was extremely inefficient.

Batch system

When the transistor appeared, the second-generation computer was born, and its size and reliability were greatly improved. In order to make better use of the computer's performance, batch processing systems have also appeared. The batch processing system is to hand over a batch of jobs to the operating system, and then the resident monitor program (Monitor) to control the operation and scheduling of the job, without manual intervention, greatly improving the efficiency of the computer.

A bit similar to the assembly line of a factory, the CPU is the worker. A batch of products to be processed is transferred from the conveyor belt, and then workers process the products in turn.

Multiprogramming system

A disadvantage of batch processing systems is that they do not take into account the parallelism of program execution. For example, a program has to wait for I/O operations before it can continue to run. When waiting, the CPU is also spent there, wasting time. For example, the assembly line suddenly stopped for a while, and the workers rested there. In order to better squeeze the performance of the CPU, a multi-program system appeared.

That is, there are multiple jobs in the memory at the same time, running interspersed with each other under the control of the management program . When a program needs to wait, it immediately switches to another job, which improves CPU utilization.

It can be seen from the comparison chart that the CPU running time in a multi-program system is obviously longer than that of a single-program system, and there is almost no rest. Therefore, the multi-program system is the black-hearted boss, which has fully drained the labor force of the CPU, making the CPU miserable.

Time-sharing system

Although the multi-program system has improved CPU utilization compared to the batch system, it can only run one program at a time, which is still rejected by the boss. The multi-program system then exits the arena and concentrates on practicing. When they came out of the mountain, the world had long forgotten the name of the multi-program system, and the only thing that was well-known was the time-sharing system that made the shadowless hand superb .

That's right, the time-sharing system is an advanced version of the multi-program system, which is essentially the switching of operations. However, the operating system allocates a certain amount of CPU time to each program, and immediately switches to another program when the time for one program ends. Because the time slice of the CPU is short enough and the switching time is fast enough, the user cannot feel the program switching, and mistakenly think that multiple programs are running at the same time.

Operating system operation

When the developer writes the code, it may be unintentional, or it may cause program errors deliberately, and some serious errors may damage other programs or operating systems. Therefore, the operating system must be designed to ensure that wrong programs or malicious programs will not affect the normal operation of other programs and the operating system.

Dual mode operation

The dual mode separates the user program from the system program. The user program runs in the user mode and the system program runs in the kernel mode. If there is an exception in the user program, it will immediately switch to kernel mode and hand it over to the operating system for processing. Those instructions that may cause damage are called privileged instructions, and privileged instructions cannot be executed in user mode. When a user program needs to call system services, it must switch from user mode to kernel mode to run.

This mode bit is in the computer hardware. With it, user programs and system programs can be distinguished.

I/O and memory protection

In order to prevent user programs from performing illegal I/O operations, all I/O instructions are privileged instructions. I/O operations cannot be executed in user mode, and can only be switched to kernel mode for execution. Controlling I/O can effectively reduce the occurrence of illegal I/O.

In a multi-program system, multiple programs run in memory. In order to ensure that applications cannot illegally access the memory space of other applications, a memory protection mechanism appears. This requires hardware support, such as base address registers and limited length registers.

In this picture, the cooperation of the two registers limits the program to only access the memory space between 300040 and 420940.

Timer

What if there is an infinite loop in a program now and it is occupying the CPU for a long time? In this way, the control right is always in the hands of the user program, this is not enough. In order to ensure that CPU control is in the hands of the operating system, a timer can be used. The timer has a fixed timer and a variable timer. After the specified time is reached, an interrupt is generated, and the user mode is switched to the kernel mode. In this way, the control power is returned to the operating system, ensuring the normal operation of the system.

Operating system function

Process management

The core goal of an operating system is to run programs, that is, how to manage the CPU. A running program is called a process. Process management solves the running problem of the program. The operating system is responsible for the following activities related to process management:

  • Create and delete users and system processes
  • Pause and resume processes
  • Provide process synchronization mechanism
  • Provide process communication mechanism
  • Provide deadlock handling mechanism

Memory management

Only the process can not meet the needs of the program to run, but also needs memory. Because the CPU can only directly access three types of storage devices: registers, caches, and memory, all the data before and after a process is processed, the instructions executed are in the memory. The memory management activities that the operating system is responsible for include:

  • Record which part of the memory is being used and by whom
  • When there is memory space, decide which processes can be loaded into memory
  • Allocate and release memory space as needed

To summarize: memory management provides functions such as memory allocation, recycling, address translation, sharing, and protection. Improved memory utilization and access speed, thereby improving computer operating efficiency.

File management

Process management and memory management solve the running problem of the program, but the memory cannot store data for a long time, so there is a file. Since the file needs to be stored, the file must be managed, so the file management solves the computer storage problem. Modern operating systems are mainly used for file management in a tree structure of directories. The operating system is mainly responsible for the following activities related to file management:

  • Create and delete files
  • Create and delete directories to organize files
  • Provide primitives for operating files and directories (program segments composed of several instructions)
  • Map files to secondary storage devices such as disks
  • Back up files on stable storage media

I/O device management

One of the purposes of the operating system is to hide the characteristics of specific hardware devices from users. I/O device management is responsible for managing a wide variety of I/O devices and solving the problem
of input and output of information in the computer .

to sum up

This article mainly introduces the operating system briefly. It is divided into four sections. The first two sections discuss what an operating system is and introduce the development of the operating system. The next two sections introduce the operation and functions of the operating system, and understand what the operating system can do from a macro perspective.

Codeword is not easy, if you can, give me a 点赞, 收藏, 关注

if you like my article, welcome attention to the micro-channel public number " R O b O d "

Guess you like

Origin blog.csdn.net/weixin_43461520/article/details/108427132