Comprehensive Analysis of Chapter 6-Process

Source: Internet
Author: User

Reprinted Please note: http://blog.csdn.net/zgh1988/article/details/7371754

At the beginning of the learning process, each of us may have encountered such a problem. Let's take these questions to understand the process.

1. What is a process?

2. What is a multi-process?

3. What do I need to execute a process?

4. How is scheduling between multiple processes?

5. What is the context of a process?

6. How to create a new process?

I. What is a process?

During the interview, HR sometimes asked the following question: what is the difference between a program and a process?

If we answer HR through a blunt concept, it will often disappoint HR. Next I want to answer the HR question through a scenario in my life.

On weekends, Mr. Zhang wants to cook a dish for his beloved wife-beef ribs soup. He has recipes for this dish, and beef ribs, MSG, spices, and so on in the kitchen, mr. Zhang made this dish for his wife step by step based on the recipe-beef ribs soup. His wife is very happy and happy.

In this metaphor, the recipe for laying beef and pork ribs is a program. Mr. Zhang should be a processor (CPU), and all kinds of ingredients for this dish (beef and pork ribs, green onions, etc.) are input data, A dish of fragrant beef ribs is the output data, and the process is the sum of the series of actions that Mr. Zhang made according to the recipe.

So we know that the program is static and the process is used to describe the dynamic process.

2. What is multi-process?

As we all know, the current operating system supports multiple processes, that is, one CPU can support multiple processes. What is the situation? Let me modify the above scenario.

On weekends, Mr. Zhang wants to cook a dish for his beloved wife-beef ribs soup. He has recipes for this dish, and beef ribs, MSG, spices, and so on in the kitchen, mr. Zhang started to make beef and bone soup, and his son's hand was cut by a knife. He cried and ran to his father to complain. At this time, Mr. Zhang stopped his work, on the menu, remember where he did it. Then he took out an emergency manual and followed the instructions above to wrap his son's hand injury. Then he went back to the kitchen and made his own beef ribs soup.

In this scenario, there are two processes. One is beef ribs soup, and the other is to wrap the wound for the son.

Mr Zhang (CPU) First executes process 1. Before process 1 is completed, process 1 is paused and process 2 is executed. After process 2 is executed, return to continue process 1 until process 1 ends. This process becomes a "Switch" between processes ".

The following figure shows the relationship between multiple processes:

Figure (a): A process table containing four processes

Figure (B): four processes are completely independent.

Figure (c): four processes are switched, but only one process is running at any time.

As a result, we know that a process has its own goals at a macro level and is controlled by the control of the process scheduling module. At the micro level, you have your own code and data, as well as your own stack. However, the system resources are used.

3. What do I need to execute a process?

Each process contains its own code, data, and stack, and is scheduled by the process scheduling module.

4. How is scheduling between multiple processes?

Multi-process scheduling is completed by the process scheduling module. First, we need to understand the state of the process, which is the relationship between the three states:

In this book, the author only introduces 2 and 3, that is, the Conversion Relationship Between ready-run-ready. Condition 2 indicates that the scheduling module selects one of the processes to run.

Condition 3 indicates that the clock is interrupted, and the scheduling module transfers the running process to the ready queue.

5. What is the context of a process?

When Mr. Zhang is going to wrap his son's wounds, he needs to record on the recipe where he made his beef ribs soup, so that he can continue after returning. Similarly, the operating system must record the context of the process during system switching.

So we created a data structure, processcontrol block, which mainly includes the following information:

1. process identifier name: each process must have a unique identifier, which can be a string or a number.

2. Current Process status: status of the process. For ease of management, the system designs processes in the same State to form a queue, such as the ready process queue. To block processes, multiple waiting queues should be formed based on the waiting events, such as waiting for the printer queue, waiting for the disk I/O to complete the queue, and so on.

3. The corresponding program and data address of the process to associate the PCB with its program and data.

4. Process Resource list. Lists All resource records except CPU resources, such as owned I/O devices and opened file lists.

5. Process Priority priority: the priority of a process reflects the degree of urgency of the process, which is usually specified by the user and set by the system.

6. CPU status in the CPU Field Protection Zone: when a process cannot continue to occupy the CPU for some reason (such as waiting for the printer) and releases the CPU, various CPU status information should be protected, in order to obtain the CPU status again in the future, continue to run.

7. Process Synchronization and communication mechanisms are used to implement semaphores required for mutual exclusion, synchronization, and communication between processes.

8. The link of the PCB in the queue where the process is located. According to the current state of the process, the pcb of the process participates in different queues. The PCB link indicates the first address of the PCB of the next process in the queue where the process is located.

9. Other process-related information. Such as process accounting information and CPU usage time.

Each process has its own process control block. We organize these process control blocks together and store them in a structure array called process table.

In this book, in line with simple and practical principles, our process control block only contains process identifiers, CPU Field Protection (that is, register content), and local descriptors. The program content is as follows:

/* Register */typedef struct s_stackframe {t_32 GS; t_32 FS; t_32 es; t_32 Ds; t_32 EDI; t_32 ESI; t_32 EBP; t_32 kernel_esp; t_32 EBX; t_32 edX; t_32 ECx; t_32 eax; t_32 retaddr; t_32 EIP; t_32 Cs; t_32 eflags; t_32 ESP; t_32 SS;} stack_frame; /* PCB Process Control Block */typedef struct s_proc {stack_frameregs;/* Register */t_16ldt_sel;/* LDT Select Sub */descriptorldts [ldt_size];/* ldts */t_32pid; /* process Number */charp_name [16];/* name */} process;

6. How to create a new process?

First, we need to apply for a process control block (PCB), then allocate resources for the new process (stack in this program), and then initialize the process control block, finally, add the queue to the ready queue (this program is the process ).

In this program, we do this.

A comprehensive analysis of the "hands-on writing Operating System" Chapter 5-makefile http://blog.csdn.net/zgh1988/article/details/7338380

Comprehensive Analysis of the "do-it-yourself write Operating System" Chapter 5 --- loading kernel. Bin http://blog.csdn.net/zgh1988/article/details/7329941

A comprehensive analysis of the "write your own operating system" Chapter Five --- Red Hat 9.0 installation process http://blog.csdn.net/zgh1988/article/details/7315676

A comprehensive analysis of the "hands-on writing Operating System" Chapter 4 --- fat12 File System http://blog.csdn.net/zgh1988/article/details/7284834

Comprehensive Analysis of the "hands-on write Operating System" Chapter 4 --- loading loader. Bin http://blog.csdn.net/zgh1988/article/details/7291909

Comprehensive Analysis of the "write your own operating system" Chapter III --- enter the protection mode http://blog.csdn.net/zgh1988/article/details/7098981

Comprehensive Analysis of "self-writing Operating System" Chapter 3 --- "real mode -- protection mode -- real mode" http://blog.csdn.net/zgh1988/article/details/7255804

Comprehensive Analysis of the "do-it-yourself write Operating System" Chapter 3 --- stack section of the work mode http://blog.csdn.net/zgh1988/article/details/7256254

A comprehensive analysis of the "write your own operating system" Chapter 3 --- privileged level and jump between different privileged level code segments http://blog.csdn.net/zgh1988/article/details/7262901

Comprehensive Analysis of "self-writing Operating System" Chapter 3 --- paging mechanism http://blog.csdn.net/zgh1988/article/details/7270748

Comprehensive Analysis of the "hands-on writing the Operating System" Chapter III --- interrupt mechanism http://blog.csdn.net/zgh1988/article/details/7276259

Comprehensive Analysis of the "self-writing Operating System" Chapter 2 http://blog.csdn.net/zgh1988/article/details/7062065

Comprehensive analysis of the first chapter of "self-writing Operating System" http://blog.csdn.net/zgh1988/article/details/7060032

"Write the operating system yourself" read Sense http://blog.csdn.net/zgh1988/article/details/7059936

 



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.