Operating system principles-8-CPU management, Processes

Source: Internet
Author: User
Knowledge points of this chapter: 1. process sequence and concurrency 2. Time-related errors 3. Related critical section 4. Process mutex 5. Process Synchronization 6. Process Communication 7. Thread Concept

Self-study requirements in this chapter: Understanding "processes" is the basic execution unit in the operating system. In a multi-program design system, many processes often exist at the same time, and they need to take the processor in turn. These cross-execution concurrent processes may be irrelevant or related to each other. A time-related error occurs when concurrent processes compete to share resources. Therefore, Process Synchronization and mutex measures should be used to reasonably use the shared resources to ensure system security. When the process must communicate with each other through information exchange, process communication can be used.

Key points: analyze time-related errors, use PV operations to synchronize and mutex processes, and use a mailbox to implement process communication.

I. process sequence and concurrency (understanding)

Some people say that there are not jump statements and repeated statements in the program. How is it sequential execution? Note: this refers to the process execution in the processor. Because the processor can only execute one operation at a time, each command must be executed in the CPU in sequence. If one command is redirected, after this command is executed, the command directed to the destination address is taken out to run on the CPU, which is specified by the program. For the CPU, the process is always executed in order.

A process is an execution of a program on a dataset. The running results of the same program and the same dataset must be the same. This is reproducibility.

Simultaneous execution is not really the same, because at any time the CPU can only run one process.

1. process sequence: the execution of any process on the sequential processor is strictly in order. This is the sequence of processes. When a process is executed in an exclusive processor order, it has two features: 1. Closed 2. reproducible.

2. Simultaneous execution of processes: In a multi-channel program design system, before all the work of a process is completed, another process can start to work, and their execution repeats in time, we call them "executable at the same time ".

3. Process concurrency: if a group of processes can be executed at the same time in the system, the group of processes is concurrency and the processes that can be executed at the same time are called "concurrent processes ".

4. Relationship between concurrent processes: the relationship between concurrent processes may be irrelevant or interactive. if the execution of a process does not affect the execution of other processes and has nothing to do with the progress of other processes, that is, they are independent of each other, then these concurrent processes are independent of each other. If the execution of a process depends on the execution of other processes, there will be interactions between these concurrent processes.

Ii. Time-related errors (Simple Application)

1. The execution speed of a concurrent process depends on itself and the process scheduling policy. A process is interrupted when it runs, and the breakpoint is not fixed. After a process is interrupted, which process can run and when the interrupted process occupies the processor, is related to the process scheduling policy. Therefore, the process execution speed cannot be determined by yourself.

2. A time-related error occurs when concurrent processes use shared resources alternately. The impact of a process on another process is unpredictable due to resource sharing and the randomness of concurrent process execution. The cause of the error is related to the time occupied by the process, the speed of execution, and the influence of the outside world. Therefore, it is called a time-related error.

3. Analyze the time-related errors in the concurrent process. Please understand the example in the textbook.

3. Related critical section (comprehension)

1. Definition of critical section: the program segment related to shared variables in a concurrent process is called a "critical section"

2. What is a related critical section? The related critical section refers to the program segments involving the same variables in a concurrent process.

3. management requirements for related critical zones.

1) A process can be executed in the critical section at most once. When a process is in the critical section, other processes that want to enter the critical section must wait.

2) any process that enters the critical section must exit the critical section within a limited period of time, that is, no process should stay in its own critical section infinitely.

3) A process cannot be forced to enter its critical section infinitely, that is, when the process exits, a process waiting to enter the critical section should enter its critical section.

4. Process mutex (Integrated Application)

1. Process mutex meaning: Process mutex means that when several processes use a shared resource, at most one process can be used at any time, other processes that want to use the resource must wait until the resource owner releases the resource. PV operations are two processes, one of which controls one signal S, assuming S is the number of red lights.

Before entering the critical section, each process must perform the P operation. When you exit the critical section, perform the V operation. It is easy to understand with the following metaphor:

Tree (S) in front of the critical section)

Used to hold red lights

The process wants to enter the CPU door

First, you have to go to the tree to get the lamp (call the p operation once)

Take the next knock (S = S-1)

If there is no light on the tree (S ≤ 0)

Tree says you owe a lamp (when S is negative)

Have no choice but to queue outside (W ait (S ))

Continued running of the lighting Process

Go out after running (call the V operation once)

Return a lamp immediately (S = S + 1)

If there is a process in debt collection (S ≤ 0)

Put it in to complete (R elasticsearch (S ))

2. Implement the PV operation, a tool for mutually exclusive processes.

A pv operation is composed of two operations: P operation and V operation. The P and V Operations are two processes that operate on semaphores. Assume that the semaphores are represented by S. The two processes are recorded as P (S) and V (S). Their definitions are as follows: Procedue P (Var S: Semaphore); begin S: = S-1; if S <0 then W (S) end; {P} Procedue V (Var S: Semaphore); begin S: = S + 1; if S <= 0 then R (S) end; {V}

To ensure the correct execution of PV operations, P (S) and V (S) operations are not interrupted. This non-disruptive process is called the "primitive ".

3. General Form of managing related critical zones with PV operations

A semaphore is associated with a group of related critical zones involving shared variables. The initial value of the semaphore is set to "1"

Before a process enters the critical section, it calls the P operation. After the operation is performed in the critical section, it calls the V operation when exiting the critical section.

Since the initial value of the semaphore is "1", the P operation restricts only one process to enter the critical section at a time. The other processes to enter the critical section must meet the first requirement for the management of the critical section, that is, a process can be executed in the critical section at most once. After the process exits, execute the V operation. If a process is waiting, release a process, in this way, the second and third requirements for the management of critical zones are met (that is, they cannot stay infinitely or wait infinitely ).

4. Analyze the process mutex problem and use PV operations to achieve process mutex.

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.