Talk about the operating system

Source: Internet
Author: User

Before getting to the point, ask, what is the operating system, and what is the difference between it and a normal application? This problem is not difficult, but it is closely related to what I want to talk about today. I would like to talk about my understanding, I think the operating system is an abstraction, this abstraction is people after a long time of practice and induction, in the absence of the operating system, people still have the means to make programs and run on the machine, but people must be targeted at hardware programming, this method is very cumbersome and a lot of repetitive work. It is slowly discovered that the program can be abstracted from the use of hardware resources, and provide a corresponding programming interface, so that the program does not need to be directly oriented to hardware writing. This not only simplifies the programming of the program, but also makes the program more portable. The result of this abstraction is the advent of the operating system, which provides abstraction of the processor, abstraction of the memory, and so on. In this way, our application can be written only for the operating system, and the application runs on the operating system, and the operating system becomes the platform to host those applications. However, with the development of the computer, the platform also appeared many kinds of platform-oriented program is difficult to run on other platforms, which has become a huge obstacle to program portability, resulting in a similar Java Virtual machine (JVM) This more advanced abstraction, the program only needs to be written for the virtual machine, The Java language is also popular without the need to consider a specific platform to run. If we can understand the principle that the operating system abstracts the hardware, I think even if we do not need to implement an operating system ourselves, this will give us a great inspiration for the application writing. Next I'll talk about some basic concepts and principles in the operating system.

Processes and Threads

A process is also an abstraction, which is an abstraction of an operating system's instance of a program execution. Process is the basic unit of the operating system to allocate resources, a program will have at least one process, the operating system will allocate a separate memory space for each process, and one process can not access the address space of another process, if you need to obtain resources in other processes, it will be through interprocess communication, such as through the pipeline, Files, sockets, and so on. Each process contains a Process Control block (PCB) that uniquely identifies a process and the operating system schedules the process based on the PCB. Compared to the process, the thread is a lot lighter, the process can be said to be the container of the thread, the thread is the executing entity in the process, a process contains at least one thread, the CPU resources are eventually allocated to the thread. A thread in the same process shares the resources assigned to the process, but each thread has its own registers and stacks. For example, to complete a cooking task, the first to assign a kitchen, which is like creating a process and allocate resources for it, some people in the kitchen to wash vegetables, some people tube boiling water, some people tube cooking, some people tube cooking, and each of the specific work is like a work thread, These threads share the resources of the kitchen, and when the cut-off people cut the vegetables, the cooks can see them because they are in the same room. But each thread also has its own small piece of resources (registers and stacks), which is like the chopping board that the cut-out person uses to make it impossible for people to boil water. But these are not guaranteed to cook the task can be completed normally, such as the kitchen each person to do the specific task is ordered, the person must wait for the vegetable wash to continue, he can not wash the dishes to fry, so the thread needs to be synchronized . At the same time, some of the necessary resources can not be shared, such as toilets, cooking people to the toilet, the other people have to wait for him to come out to go in, so the thread also need to be mutually exclusive . When these rules are met, the task of cooking can be done in a methodical manner without any mistakes. In fact, many times the abstract things and the real world of the phenomenon of analogy, a lot of confusing things are easy to understand.

Process scheduling algorithm

The Process Control block (PCB) is also mentioned above, which stores information about the process, including scheduling information for the process. After the process is submitted to the operating system and not directly into the running state, they are first placed in a data structure called the Ready queue, indicating that the processes are ready to run. process scheduling is to select the appropriate process allocation processor from the ready queue to get it into a running state. Here are a few common process scheduling algorithms.

    1. first come first service scheduling algorithm : As the name implies, the process of first entering the ready queue first gets the processor, enters the running state, until the end of the operation or blocking, before abandoning the processor.
    2. Short job priority scheduling algorithm : Select a process in the ready queue that estimates the shortest running time, and assign the processor to run until it is complete or blocked before discarding the processing machine.
    3. Priority-based non-preemptive scheduling algorithm : Select the highest-priority process in the ready queue, assign a processor to it, and then let the process run until it ends or blocks before discarding the processor.
    4. Priority-based preemptive scheduling algorithm : Select the highest-priority process in the ready queue and assign the processor to execute it, but during its run, a higher-priority process occurs in the ready queue, which stops the current process. and assign the processor to a higher priority process. Therefore, the algorithm can better meet the needs of emergency operations, and is often used in real-time systems.
    5. High response ratio priority scheduling algorithm : Response ratio = response time/Request Service time = (wait time + request service time)/Request service time. Therefore, the longer the process waits, the less time it needs to be served, and the higher its response. This takes into account the process waiting time, but also takes care of the process of short running time, is a more fair scheduling algorithm. However, the response to the process needs to be calculated before scheduling, which increases the overhead of the system.
    6. time slice rotation scheduling algorithm : Each time the dispatch, the processor is assigned to the first team process, and let it execute a time slice, when the time slice is exhausted, the scheduler stops the process execution and joins it to the end of the ready queue. The processor is then assigned to the new team first process in the ready queue.
    7. Multilevel feedback queue scheduling algorithm : Set up multiple ready queues, give each queue a different priority, and the higher the priority queue, the smaller the time slices allocated for each process. When a process into the memory, first put it at the end of the highest priority queue, according to the first-come-first service algorithm waiting for scheduling, when it executes, if it is not in the specified time slice of the end of the run, it is added to the second level of the ready queue, the same as the FCFS algorithm waiting for scheduling, and so on. A process in a low-priority queue is scheduled to execute only if the high-priority queue is empty. and processes in the high-priority queue preempt the processor that is executing the process in the low-priority queue.
Paging and page substitution algorithms

We know that by paging, you can make a part of a data structure stored in memory and the other part saved on disk. This way, when there are no pages in memory, it is necessary to put the pages in the disk into memory and select a page in memory to be eliminated. and the page replacement algorithm is to determine which page to eliminate the algorithm.
1. Best permutation algorithm : Each page in memory can be tagged with the number of instructions that need to be executed before the page is first accessed, displacing the most marked pages. However, because when a page fault occurs, the operating system cannot know the next time the individual pages are accessed, so the algorithm is not possible, but it can be used as a measure of other algorithms.
2. FIFO replacement algorithm : Every time a page fault occurs, the earliest entry into memory is always eliminated.
3. the most recent unused (LRU) permutation algorithm : When a page fault occurs, eliminate pages that have not been used for the longest time in the most recent time.
4. The least recently used displacement algorithm : When the page is missing, eliminate the most recent time the least number of pages.

Summarize

Learning the meaning of the operating system is what, I think the operating system is a methodology, we write programs encountered a lot of problems, the operating system has given a reference to a very good solution. At the same time, understanding the operating system on the hardware, the application of the idea of abstraction, I think it will also be of great benefit. However, the fact that the more you learn, the more you find that you understand the less, so learning, come on, boy!

Talk about the operating system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.