The first assignment: Analysis of the Linux system

1. The composition of the operating system

1. A processless kernel

            In some operating systems the kernel of the operating system executes out of all processes. That is to say, the operating system has its own memory area and system stack. When an interrupt, trap or system call occurs in a process, the context of the process is saved in the system stack, and the control is transferred to the kernel. After the operating system finishes executing, it restores the context of the process, and the process continues to execute, or saves the context of the process, and then assigns another process to execute.

   

                

2. Execute in the user process

                In the n process images managed by the operating system, there are not only the process control block, the user stack and the user-specific data space, but also the kernel stack and the operating system code shared by all processes.
 
    
                                                                                
 
 
 

      When an interrupt, trap or system call occurs, the processor is placed in kernel mode, control is handed over to the operating system, and the process context is saved for mode switching. When the interruption is completed, the resume process continues execution or transfers control to the process switching routine for process switching, so that only mode switching is required during the process of interrupting and resuming execution, and no process switching is required, thereby reducing overhead.

 

 

                        

 

3. Process-based operating systems

                  Execute the operating system as a set of ordinary system processes, that is, when a process is interrupted, trapped or system called, the processor changes to kernel mode, the process switching routine switches to the system process, and the context execution of the user process is saved The environment, that is, the kernel functions are organized into independent processes. When the terminal ends, resume the user process to continue execution, the processor changes to user mode, and the process switching routine switches the system process to the user process, or transfers the control right to the dispatcher to execute the next process.

 

  

 2. Process state transition

1. The status of the Linux process is:

TASK_RUNNING : Ready state or running state, the process is ready to run, but not necessarily occupying the CPU, the R corresponding to the process state

TASK_INTERRUPTIBLE: Sleep state, but the process is in shallow sleep and can respond to signals. Generally, the process is in the state where the process actively sleeps, corresponding to the process state S

TASK_UNINTERRUPTIBLE: Sleep state, deep sleep, do not respond to signals, the typical scenario is that the process acquires semaphore blocking, corresponding to process state D

TASK_ZOMBIE: Zombie state, the process has exited or ended, but the parent process does not yet know, the state when there is no recycling, corresponding to the process state Z

TASK_STOPED: stop, debugging state, corresponding to process state T

2. Process scheduling timing:

Process scheduling will cause process state transition. From the above figure, it can be seen that the following conditions will trigger scheduling. When the process terminates or the process sleeps, it actively exits or sleeps to release the CPU; the light sleep process is selected by CFS scheduling to wake up, and the deep sleep process locks due to the semaphore. It is awakened by the release of waiting; the process receives a semaphore, etc.; there is also one of the most common interrupts, exceptions.

 3. How the process is scheduled

Whether in batch or time-sharing systems, there are typically more user processes than processors, which causes them to compete for processors. In addition, system processes also need to use the processor. This requires the process scheduler to dynamically assign the processor to a process in the ready queue to execute it according to a certain strategy.

  Common process scheduling algorithms of operating systems:

  1. First come first served (FCFS, first come first served)

  Among all scheduling algorithms, the simplest is the non-preemptive FCFS algorithm.

  Algorithm principle: Processes use the CPU in the order in which they request the CPU. Just like when you buy something to queue, whoever is first in the queue will be executed first, and it will not be interrupted during its execution. When other people also want to enter the memory to be executed, they have to wait in line. If something happens during the execution process, he doesn't want to queue now, and the next one in the queue will make up. At this time, if he wants to queue up again, he can only stand at the end of the queue.

  Algorithm advantages: easy to understand and simple to implement, only need one queue (FIFO), and fairly fair

  Disadvantages of the algorithm: it is more conducive to long processes, not conducive to short processes, it is beneficial to processes with busy CPU, and it is not conducive to processes with busy I/O

  2. Shortest Job First (SJF, Shortest Job First)

  Shortest Job First (SJF, Shortest Job First) is also known as "Shortest Process First" SPN (Shortest Process Next); this is an improvement to the FCFS algorithm whose goal is to reduce the average turnaround time.

  Algorithm principle: Prioritize the allocation of processors to processes with short expected execution times. Usually later short processes do not preempt the executing process.

  Advantages of the algorithm: Compared with the FCFS algorithm, the algorithm can improve the average turnaround time and the average weighted turnaround time, shorten the waiting time of the process, and improve the throughput of the system.

  Disadvantages of the algorithm: It is very unfavorable for long processes, and may not be executed for a long time, and the priority of execution cannot be divided according to the urgency of the process, and it is difficult to accurately estimate the execution time of the process, thus affecting the scheduling performance.

  3. Highest Response Ratio Next (HRRN, Highest Response Ratio Next)

  The highest response ratio priority method (HRRN, Highest Response Ratio Next) is a comprehensive balance of the FCFS method and the SJF method. The FCFS method only considers the waiting time of each job and does not consider the length of the execution time, while the SJF method only considers the execution time and does not consider the length of the waiting time. Therefore, these two scheduling algorithms will bring some inconvenience in some extreme cases. The HRN scheduling strategy also considers the waiting time of each job and the estimated execution time, and selects the job with the highest response ratio for execution. In this way, even for a long job, as its waiting time increases, the W/T also increases, and there is a chance to get scheduled execution. This algorithm is a compromise between FCFS and SJF.

  Algorithm principle: The response ratio R is defined as follows: R = (W+T)/T = 1+W/T

  Where T is the estimated execution time of the job, and W is the waiting time of the job in the standby state queue. Whenever a job is scheduled, the system calculates the response ratio of each job, and selects the one with the largest R to be executed.

  Advantages of the algorithm: Since long jobs also have the opportunity to be put into operation, the number of jobs processed at the same time is obviously less than that of the SJF method, so the throughput of the HRRN method will be smaller than that of the SJF method.

  Disadvantages of the algorithm: Since the response ratio needs to be calculated before each scheduling, the system overhead will also increase accordingly.

  4. Time slice rotation algorithm (RR, Round-Robin)

  The algorithm employs a deprivation strategy. Time slice round-robin scheduling is one of the oldest, simplest, fairest and most widely used algorithms, also known as RR scheduling. Each process is assigned a time period, called its time slice, which is the time the process is allowed to run.

  Algorithm principle: Let the ready process use the CPU scheduling method in turn according to the time slice in the way of FCFS, that is, all the ready processes in the system are arranged in a queue according to the FCFS principle, and the CPU is assigned to the queue head process every time it is scheduled, so that it Execute a time slice, the length of the time slice is from a few ms to several hundred ms. At the end of a time slice, a clock interrupt occurs, and the scheduler suspends the execution of the current process accordingly, sends it to the end of the ready queue, and executes the current queue head process through context switching. The process can not use up a time slice, Just give up the CPU (eg block).

  Algorithm advantages: The time slice round robin scheduling algorithm is characterized by its simplicity and short average response time.

  Algorithm Disadvantages: Not conducive to handling urgent jobs. In the time slice rotation algorithm, the size of the time slice has a great impact on the system performance, so the size of the time slice should be selected appropriately

  How to determine the size of the time slice:

  1. System requirements for response time

  2. The number of processes in the ready queue

  3. The processing capacity of the system

  5. Multilevel Feedback Queue

  The multi-level feedback queue scheduling algorithm is a CPU processor scheduling algorithm, which is adopted by the UNIX operating system.

  Multi-level feedback queue scheduling algorithm description:

  1. When the process enters the queue to be scheduled and waits, it first enters the Q1 with the highest priority to wait.

  2. Schedule the processes in the queue with high priority first. If there is no scheduled process in the queue with the higher priority, the process in the queue with the lower priority is scheduled. For example: Q1, Q2, Q3 three queues, Q2 will be scheduled only when there is no process waiting in Q1. Similarly, Q3 will be scheduled only when Q1 and Q2 are empty.

  3. For each process in the same queue, schedule it according to the time slice round-robin method. For example, the time slice of the Q1 queue is N, then if the job in Q1 has not completed after N time slices, it will enter the Q2 queue and wait. If the job cannot be completed after the time slice of Q2 is used up, it will continue to the next level queue until completion.

  4. When the process in the low-priority queue is running, there are newly arrived jobs, then after running this time slice, the CPU is immediately allocated to the newly arrived jobs (preemptive).

  In the multi-level feedback queue scheduling algorithm, if the time slice of the first queue is specified to be slightly larger than the processing time required for most human-computer interactions, it can better meet the needs of various types of users.

4. My views on the process model of the Linux operating system

  I think the operating system is the interface between the user and the computer. On the one hand the operating system manages all computer system resources, on the other hand the operating system provides the user with an abstract concept of the computer. With the help of the operating system, the user uses the computer , avoids direct manipulation of computer system hardware. 

  For a computer system, the operating system is a collection of programs that manage all system resources.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325100393&siteId=291194637