Operating System-algorithm summary, operating system-Algorithm
The application of various algorithms in the operating system makes the various components of the computer system coordinate the work, so that the resource utilization and program execution are more reasonable and efficient. Compared with our daily life, the operating system is like a department store, and the algorithm is used to maximize the profit of the store.
[Two-Level Processor Scheduling] the two-level scheduling here is:
Job Scheduling and Process Scheduling. We know that the program and data are stored in external memory. Before execution, the program must first be delivered to the memory, and then the process starts from the ready state to the end of running. The input well on the disk is transferred to the main memory for job scheduling; process Scheduling is called until the execution ends.
Job Scheduling Algorithm:
First
Service firstIt is like waiting in the queue. We can buy meals first, which reflects the fairness of time. Let's look at a simple example:
In a multi-channel Program System, the user space is set to 100 kb. The primary storage space management adopts the first allocation policy to adapt to, and the first service algorithm to manage jobs. List the start time, completion time, and turnaround time of each job.
Resolution:
First, the question shows that the user can use the primary storage as 100 kb. Therefore, when the job is put into the primary storage, pay attention to the insufficient memory. The steps are parsed as follows: 1. determine the start time, the completion time, and the time when the primary storage is loaded. Because a single-core system can only access one job at a time, the completion time of the previous job is the start time of the next job. 2. the service should be started first. job3 should have been earlier than job4, but job1 and job2 should have been completed first until 9, and the memory between 8-9 is only 20 K, so job3 cannot be put down. Therefore, job3 is skipped, put job4 first, and the time it enters the memory = the time it enters the input well. 3. determine the memory entry time of job3. Although job1 has been completed at, job2 and job4 still occupy 80 KB of memory. Therefore, job3 can only be put into memory when job2 is completed, that is, 9.6. 4. Note: turnaround time = Execution End Time-enter the input well time.
Short-Time Priority AlgorithmWhen the memory can still load multiple jobs at the same time, follow the first-come first-served algorithm to execute. If you encounter two job3 problems, consider the first execution with a short computing time: for example, to add job5: When the loading time is 8.7, it takes 0.4 hours to calculate the size of the primary storage is 25 KB. After job4 is executed, job5 instead of job3is executed.
High Response Ratio Priority Algorithm: Response Ratio = Waiting Time/computing time
Wait time = last enter input well time-first enter input well time
It is easy to know from the response ratio that the execution of a program depends on the waiting time and computing time, which can avoid the execution of a program with a very short execution event waiting too long. [Process scheduling algorithm] process scheduling refers to the scheduling of processes in the ready queue when executing programs in the memory. Compared with job scheduling, the Service algorithm does not need to consider the memory, because the job has formed a queue of processes from the memory, which can be executed in the first order. Highest-priority scheduling: pre-determine the level of the process so that high-priority scheduling can be performed first. It can also be divided into preemptible and non-preemptible processes. It refers to whether a high-priority process will occupy the processor occupied by the existing process. Time slice rotation scheduling requires that a process execution takes up to the processor time. If the time limit is exceeded, the processor must be transferred out. [Page scheduling]
The page scheduling algorithm is like a solitaire game:
First-in-first-out:
For example, in a page-based storage management system, the pages accessed by a process are 2, 3, 2, 1, 5, 4, 5, 3, 2, and 5, and three primary storage blocks are allocated. Alibaba Cloud first-in-first-out algorithm:
Resolution:
First, understand what a page is missing. Every time a primary block is occupied again, it is called a page missing.
For example, the numbers in the first and second columns are not stored before the primary storage, so they are missing pages. By the third column, there are already two in the queue, so no page is missing, there will be no changes in the queue. In this table, we can see that the first time of the team is the shortest. First, first, first, and foremost, the end is replaced by the end (the longest time ).
Other algorithms are similar.
[Summary]
Algorithms are used in computers to make program execution more efficient. It is very simple and interesting as long as we connect to life.