Document directory
- 1. Let's take a look at the process.
- 2. processor management
- 2.1 Processor Allocation Policy
- 3. Brief Introduction to various Process Scheduling Algorithms
- 4. Where to go and where to live?
An important task of the operating system is to manage the processor, which is to manage the CPU allocation. How to allocate CPU resources so that users can respond as soon as possible and improve CPU utilization is part of the processor management in the operating system.
1. Let's take a look at the process.
There are also several process definitions. Similarly, these definitions describe different aspects of the process. For example:
* A process is a unit of resource allocation.
* The process is a running command segment.
1.1 process is the unit of Resource Allocation
CPU time, I/O port, TCP/IP Port, and other computer resources are allocated by processes. Simply put, a process is the final "consumer" of a resource ".
1.2 The process is a command segment being executed
The definition of this sentence is somewhat general. In fact, it still requires a lot of additional information to support sending and executing commands and controlling these command segments. Such as program counters and process stacks.
The process is stateful, as shown in the figure:
The actual implementation is more complicated than this, but the principle is the same.
2. processor management
As we have said above, a process is the unit of resource allocation. The allocation of CPU resources is reflected in the process scheduling, that is, the process that gets the CPU time can be executed.
2.1 Processor Allocation Policy
There are some policies for process scheduling, that is, common scheduling algorithms. However, these policies usually have some advantages and disadvantages. A mom and a few children will not be 100% fair when breastfeeding. Let's take a look at common scheduling algorithms:
* Service first (FIrstCOmeFIrstSErvice)
* Short jobs are preferred (SOrtJObFIrst)
* Time slice Rotation
* Priority-based
3. Brief Introduction to various Process Scheduling Algorithms
Each scheduling algorithm is based on some simple ideas and has some advantages and disadvantages.
3.1 Service algorithms first
Algorithm: The process is scheduled to run according to the submission time.
Metaphor: Bank identification exclusion service. For a slightly larger bank, you need to get a number paper first when you are preparing to handle the business. The paper number indicates your exclusion number and the number of unserved users. Similar:
The user queues for services by number.
Advantages: Makes people feel fair (easy to implement)
Disadvantages: Imagine, after waiting for a few minutes, there is only one user in front of you. It's your turn. You are stealing. Who knows, the one before you is a big brother. I took a few cents in my hand, and it took half a day to access and view the data. When it's your turn, the bank is off duty. It's strange that you don't crash.
The official term is as follows: for some small jobs, the wait time is too long.
3.2 Short jobs are preferred
Algorithm: Priority is given to jobs that consume less CPU time.
Metaphor: During the meal, there are always people in the queue, saying: I just need to cook a dish-short jobs are preferred (specifically, they are the first to execute.
Advantages: Theoretically, this algorithm is optimal, and the average waiting time for each person is the shortest.
Disadvantages: Is it painstaking that you often don't know if someone else is cooking a dish, or is it a single dish (four dishes and one soup?
3.3 time slice Rotation
Algorithm: Divide the CPU into time slices. After each job runs a time slice, change to another job.
Metaphor(Currently missing)
Advantages: Every process has the opportunity to execute
Disadvantages: Frequent process switching is a waste of time
3.4 priority-based
Algorithm: Based on resource usage, the process is divided into three or six levels. The higher the level, the sooner the process is scheduled.
Metaphor: Based on the individual's degree, the higher the level, the higher the income.
Advantages: High CPU utilization
Disadvantages: When the level is too low, infinite waiting may occur.
4. Where to go and where to live?
This section introduces the concept of process and the main task of process management: the main strategy of process scheduling.
When talking about the process, you have to talk about process synchronization.
This is the next article.