1.0 description and control of the process

Source: Internet
Author: User

1.What is a process

In a computer, a process is the execution of a program.

Processes include:

1) The code required to execute this procedure

2) Relevant data required to execute the program

3) information required by the operating system Management process - - Process Control block

OK to understand the basic concepts of the process, the next step is to understand the specific structure of the process and how the operating system to control the process

2.status of the process

Before looking at the status of the process, review how the process works in the system.

The operating system realizes concurrent execution of multiple processes through a time-sharing mechanism. The word concurrency is used instead of parallel because there is never a parallel state for a single-processor computer, and a processor can only process a piece of code at the same time, and it can only accomplish one task, and it is impossible to implement parallel execution of the task.

In order to improve the user experience of the computer, but also in order to make reasonable use of computer resources, so that the CPU in the maximum working state, the operating system by the implementation of a way called rotation, Assigning a maximum run time (time slice) to each process results in a state of multi-process concurrency execution.

So, at a certain point in time, there are multiple processes that appear to be running concurrently, only one, or several (multiprocessor) processes are running, other processes are in other states.

So how many states does the process have?

The status of a process changes slightly depending on the implementation of the different operating systems, but the most basic is five states:

1. New status: The process has just been created and the operating system has not yet added it to the executable process group. (That is, the process was created, but not yet running, and has not been added to any queues.) -- The concept of the queue will be presented later)

2. ready state: The process is ready to wait for the processor to be allocated.

3. blocking states: Processes cannot execute until certain events occur: such as IO Operations

4. running state: This process obtains the time slice, has the control processor the right, is running the related program.

5. exit: The operating system frees the process from the running Process group, or his own cause is stopped, or canceled for some reason.

Explain:

Why is there a blocking state?

Because the computer has a different parts of the speed of the imbalance, the processor is often operating speed of the IO device Tens of thousands of times, some io devices, especially slow speed such as printers. If some processes need to use The return result of the IO device, then the processor must wait for the io device to complete the task and return to the execution result, during which time the processor is completely out of work, resulting in wasted computer resources. Thus, the operating system implements a blocking mechanism that is blocked when a process requires Time-consuming work such as IO. when io is complete, an io interrupt is generated, telling the operating system that the event has been completed, and that the task or tasks that need to wait can continue. The operating system determines which process will continue to execute based on the dispatcher.

How does the process begin?

There are typically 4 events that cause the creation of a process.

1) New batch job

2) Interactive Login

3) The operating system is created because it provides a service

4) derived from the existing process

How did the process end?

There are many behaviors that can cause the system to terminate, and the process can be terminated in any state.

The intent of termination may be that the user terminates under an interactive system, or it may be an error generated by itself or by a hardware error.

What is preemption?

Preemption This term is defined as recovering a resource that a process is using. This is a possible reason for the conversion of a run-and- ready state. When the blocking queue has a higher priority than the currently executing process, when the blocking event occurs and the high-priority process resumes to the operational state, it is possible to preempt the resources of the running process and make the current process ready.

Thread execution Trajectory

After an interrupt occurs, the program counter (PC) re-assigns a process interrupt handler , and the interrupt handler delegates the dispatcher to decide which processes to execute next.

What is a queue?

A queue is a data structure that is performed by the operating system maintenance process, using a FIFO structure to hold the tasks that are about to be performed.

The most basic queue consists of a ready queue and a blocking queue, which is inserted into the ready queue when the time slice of a process runs out and is not blocked, and a new process is removed from the ready queue to run. When a process is blocked, it is put into a blocking queue. There is a clear drawback, when a blocking event occurs, the operating system scans the entire blocking queue, the process waiting for the event into the ready queue, a real operating system blocking queue often has a large number of blocking processes, which can lead to inefficient.

So, in general, the blocking process waiting for an event is placed in a separate queue , and when the event occurs , the entire queue is put into the ready queue.

Similarly, multiple priority queues are maintained to facilitate management.

In addition to the five process states just mentioned, there is a class of States called suspend states. The suspend state is not a state, but a pair. First explain what is called the suspend state.

Because of the lack of computer resources, computer memory is an expensive resource, the development speed of memory size can not keep up with the development speed of the program resident memory size, so this greatly restricts the number of processes that are capable of running concurrently. Also, the speed of the computer IO is still too slow for CPU computing, and at some point in time, there may be a process in the queue that is completely out of readiness, all waiting for IO . Therefore, the operating system often joins a suspend state to "evict" the process waiting for IO , providing enough free memory for more processes to use.

Here comes the concept of an exchange. Swapping is an IO operation that when all the processes in memory are in a blocking state, the operating system can put one of the processes in a suspended state, transfer its memory footprint to disk, and the memory free space can be transferred to another process for use.

Then think about the hang problem, when the memory has enough space, you can choose to open a new process or choose one to run from the suspended state process. But the pending process is blocked before it hangs, how can I tell if he can execute it now? Therefore, subdivide the suspended process to determine if the pending process is ready. This is the birth of 2*2 = 4 different states

Ready state

Blocking states

Suspend blocking State

Suspend ready state

When a blocking event occurs, the blocking process that waits for this event enters the ready queue from the blocking queue, waiting for the blocking pending process of this event to enter the ready pending state. When there is enough space in memory to accommodate a new process, it is possible for a process in a ready pending state to return to the ready state to run.

The transition of the suspended state is summarized here after simplifying the actual conversion process of the operating system.

In the actual operating system, whether the suspension also takes precedence into account, if the Ready pending queue has a higher priority in a process than the ready queue, there is a possibility that processes in the ready queue will be swapped to a suspended state for higher priority processes to continue execution.

If the process involves virtual memory, the design will be more complex and remain for later discussion.

3. Management of processes

Before you manage your learning process, understand the resources that the operating system maintains for management processes.

The operating system maintains a different table in 4:

Memory: Used to track memory and external memory. The memory table includes the following information:

1. Memory allocated to the process

2. External memory assigned to the process

3. Any protection properties for memory blocks or blocks of virtual memory.

4. Any information needed to manage virtual memory

Io: io table-managed IO devices and channels in computer systems

File: Provides file presence, location of file in external memory

The rest of the process table is about the process table.

The operating system wants to manage the process, first to know the location of the process, and to know the process properties required for management.

The physical composition of a process is the memory occupied by programs, data, stacks, and properties. These elements form the process image.

Process properties can be subdivided into three categories:

Process identity information: a property used to identify a process, including (unique identifier, parent process identifier, user identifier)

Processor status information: A property that holds the runtime processor state when used for process switching.

Process Control Information: the additional information required to control and coordinate various activities.

The process Control block is accessed by a unified processing routine to control access to the process control block to protect the process control block.

Execution mode

Most operating systems support at least two execution modes, some of which can only be executed in privileged mode, and some memory areas can only be accessed in privileged mode.

Non-privileged states are often referred to as user States, and privileged States are called system states or kernel states.

The reason for using a different execution state is to protect the system from allowing the user to perform specific instructions that might affect the system.

How does the processor determine what the current execution mode is?

The PSW program status Word (part of the processor) indicates the execution mode, when the user invokes a system service or the interrupt is in the execution of the system routine, the execution mode is set to the kernel state, and the return is set to the user state.

Creation of processes

1. Assigning a unique process identifier to a process

2. Allocating space to processes

3. Initializing the Process control block

4. Set the correct link. Put the new process into the correct dispatch queue.

5. Create or augment other data structures

Switching of processes

Analysis of the process of switching, the process of switching on the macro (relative macro) is the operating system to designate another process as a running state, and give control to the process. But this raises a lot of new questions:

1. When do I switch processes?

2. What are the differences and connections between mode switching and process switching?

3. What does a process have to do with data structures?

This film is the rest of the article is to solve these problems

When do I switch processes?

Simply put, you can switch processes as long as the operating system has control.

The operating system acquires control from the running process at the following times:

1. Interrupt common interrupts (clock interrupt (time slice exhausted),io interrupt (io completion), memory failure (missing pages, and IO Similarly, as for what is called a fault, Virtual memory will refer to this noun))

2. Traps: Errors that occur in the process being executed

3. System call: Explicit request

Mode switching

If there is an unhandled interrupt, the following work occurs

1. Place the program counter at the address where the interrupt handler begins

2. Switch from user state to kernel state so that interrupt handling code can contain privileged instructions. At this point, the interrupted process context is saved in the process control block of the interrupted program.

Process switching

Obviously, unlike process transformations and schema transformations, a pattern switch can not change the state of a running process, in which case saving and recovering the context requires little overhead, but if the currently running process transitions to another state, the operating system must make a substantial change in its environment.

The complete switchover process is as follows:

1. Save the processor context

2. Update the Process control block that is currently in the running state and change its state to another state.

3. Move the process to the relevant queue

4. Select another process

5. Update the control block of the selected process to turn its status into a running state.

6. Update the data structure of memory management

7. Restore the processor state of the selected process.

1.0 description and control of the process

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.