study hard and make progress every day

This article has included to my lot DayDayUP:github.com/RobodLee/DayDayUP warehouse, welcome Star

preface

I had never systematically studied operating systems before, and I felt that I had a terrible understanding of certain concepts such as interrupts, memory, processes and threads in my normal learning process. So I plan to learn the operating system systematically. At the beginning, I watched the teacher Li Zhijun from Harbin Institute of Technology at B station, but I began to analyze the boot process from assembly code, although it was very good, but maybe I was too stupid to understand it. So I read “Operating System” of Soochow University on MOOC of Chinese university.

It’s a national gem anyway, and it’s not very well spoken, but it’s easy to accept. The book I read was Operating System Concepts, Seventh Edition.

This series of articles as I learn the operating system notes, also hope to help those who want to learn and are learning the operating system partners. Without further ado, let’s start with the formal content.

What is an operating system

This is a logical diagram of the components of a computer system. As you can see from the diagram, if you want software to run on computer hardware, you have to use the operating system. Operating system is the lowest level of computer software, is the basic support environment for the operation of applications, indispensable. But the operating system is not necessarily necessary, for example, some small computers like microcontroller can run programs even without an operating system.

So what’s the point of operating systems? I think it’s “convenient” for average users and developers. printf(“hello world!” ); You’ve all written this before, but why would a line of code like this print a sentence on the screen? Because after running this line of code, to call the interface of the operating system, and then the operating system to control the underlying hardware for related operations, for us, these are insensitive, just write a line of code.

So my understanding of the operating system is that the operating system is the butler, and the computer hardware is the house, and the user is the master of the house. For example, when we want to eat, we tell the housekeeper to cook, and then the housekeeper goes to dispatch, to arrange people to buy food, cook, and we just need to wait for the food to come to the table. If you don’t have a butler, you have to do it yourself. So with the operating system, we can be very comfortable, efficient use of computers.

Multiprogramming and time-sharing

Today’s operating systems didn’t start out that way, they have evolved in many stages.

None Operating system (Manual operation)

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

Batch system

With the advent of the transistor came the second generation of computers, which greatly increased in size and reliability. In order to be able to better play the performance of the computer, the batch processing system also appeared. Batch processing system is to give a batch of jobs to the operating system, and then the resident Monitor program to control the operation and scheduling of jobs, without manual intervention, greatly improving the work efficiency of computers.

Sort of like the assembly line in a factory, the CPU is the worker. A batch of products to be processed is sent on a conveyor belt, and workers work on the products in turn.

Multiprogramming system

A disadvantage of batch systems is that they do not take into account parallelism. For example, a program has to wait for an I/O operation before it can be run, and the CPU is wasting time while it waits. For example, there is a sudden stop on the assembly line, where the workers are resting. In order to better squeeze the performance of the CPU, multi-programming systems emerged.

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

As you can see from the comparison, the CPU running time in the multi-channel system is significantly higher than that in the single-channel system, with almost no rest. So, the multi-programming system is the boss of the black heart, fully drained of CPU labor, making the CPU miserable.

Time-sharing system

Although multiprogram systems have improved CPU utilization over batch systems, they can only run one program at a time and are still hated by the boss. Multi – program system will withdraw from the river’s lake, focus on training. By the time it came out of the mountain, the world had forgotten the name of multi-programming system, only known as the time-sharing system that played the shadowless hand to perfection.

Yes, a time-sharing system is an advanced version of a multi-programming system, essentially a job switch. But the operating system allocates a certain amount of CPU time to each program, and when one program runs out of time, it switches to another program. Because the CPU time slice is short enough, the switching time is fast enough that the user does not feel the switching and mistakenly thinks that multiple programs are running at the same time.

Operating system Operations

When developers write code, they may do so unintentionally or intentionally, causing errors that can seriously damage other programs or the operating system. Therefore, the operating system should be designed to ensure that error programs or malicious programs will not affect the normal operation of other programs and operating systems.

Dual mode operation

Dual mode separates user programs from system programs, with user programs running in user mode and system programs running in kernel mode. If a user program fails, it immediately switches to kernel mode and the operating system takes care of it. Commands that may cause damage are called privileged commands and 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 and can be used to distinguish user programs from system programs.

I/O and memory protection

To prevent the user program from performing illegal I/O operations, all I/O commands are privileged commands. The USER mode cannot perform I/O operations, but can only be switched to the kernel mode. In this way, the operating system can control I/O to effectively reduce the occurrence of illegal I/O operations.

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

In this diagram, the two registers cooperate, limiting the program’s access to 300040 to 420940 memory space.

The timer

What if a program now has an infinite loop that hogs the CPU for a long time? So the control is always in the hands of the user program. To ensure that CPU control is in the hands of the operating system, timers can be used. Timer has fixed timer and variable timer. After reaching the specified time, interrupt occurs and switch from user mode to kernel mode. In this way, the control is returned to the operating system to ensure the normal operation of the system.

Operating system Functions

Process management

The core goal of an operating system is to run programs, that is, to manage the CPU, and a running program is called a process. Process management solves the running problems 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
  • Provides a process synchronization mechanism
  • Provides a process communication mechanism
  • Provides deadlock handling mechanisms

Memory management

The process alone is not enough to run the program, it also needs memory. Since the CPU has direct access to only three types of storage devices — registers, cache, and memory — all the instructions executed by a process are in memory, both before and after it processes all the data. Memory management activities for which the operating system is responsible are:

  • Record what part of memory is being used and by whom
  • When memory space is available, determine which processes can be loaded into memory
  • Allocate and free memory space as needed

To summarize: Memory management provides memory allocation, reclamation, address translation, sharing, and protection. Improve the memory utilization rate and access speed, so as to improve the efficiency of computer operation.

File management

Process management and memory management to solve the running problem of the program, but the memory can not save data for a long time, so there are files, files to be stored on the file management, so the file management to solve the storage problem of the computer. Modern operating system is mainly based on the directory tree structure to file management, operating system is mainly responsible for the following activities related to file management:

  • Create and delete files
  • Create and delete directories to organize files
  • Provides primitives for manipulating files and directories (program segments consisting 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 an operating system is to hide the characteristics of a specific hardware device from the user. I/O device management Is responsible for managing a wide variety of I/O devices and solving information input and output problems in computers.

conclusion

This article is mainly a brief introduction to the operating system, a total of four sections, the first two sections discussed what is the operating system, introduced the development of the operating system. The next two sections describe the operations and capabilities of the operating system to give you a macro view of what the operating system can do.

Code word is not easy, if you can, give me a like, favorites, follow

If you like my article, please follow the wechat official account “R o B O D”.