Operating system-process (1)

Source: Internet
Author: User

This article describes one of the core concepts of the operating system: process, the main content:

    1. What is a process
    2. Process Creation (Creation)
    3. Termination of the process (termination)
    4. Status of the process (state)
I. What is a process1.1 Basic Information

A process is an instance of an executing program, an abstraction of a running program (abstraction) that contains all the program counters (PCS), registers, and variables that are currently running the program: the instructions and data required for the program to run.

If the program is a recipe, then the process is the process of cooking.

My current system running instance of the process (Windows 10)

If a program runs multiple times at the same time, the operating system creates multiple processes (without affecting each other), and for the operating system, there are multiple processes running the same program. Google Chrome is an example (multiple instances that don't affect each other, but consume memory resources.) )

1.2 Why Process

Why does the operating system introduce the concept of a process? Isolation is mentioned above, but isolation is not the primary driver for process introduction, and the primary driving force for the introduction process is to increase the response time of the system.

CPU can only do one thing at a time, only one process runs on the CPU, but why do we feel that the computer is at the same time the author a lot of things? We type in Word again and receive an email notification in the lower right corner.

    1. Word is a process (of course, multiple processes are open)
    2. The message is a process

Operation system to use their own scheduling strategy to let the CPU switch between word and email, because the switch is very fast, so users feel the CPU at the same time in the author a lot of things, so as to increase the effectiveness of the system response.

User feel

A, B, C processes are implemented concurrently

Actual Execution

A, B, C at the same time only one in the implementation

1.3 Process scheduling

With an example: A father is going to make a cake for his son, he has a recipe for making cakes, he is making cakes according to recipes, and suddenly his son comes in and says, "Dad, I want to drink milk." The father stopped the cake he was making , went to pour milk for his son, then warmed in the microwave and gave the milk to his son. Eventually the father went back to the place where he had made the cake and went on to finish the cake.

    1. Cake Recipe: Is the program, what to do first, what to do after
    2. The process of making a cake: Process a
    3. The process of giving your son hot milk: process B
    4. This dad: CPU
    5. The son suddenly drank milk: interrupted

The CPU switches between process A and B based on the existing situation ( policy ). Top dad went on making the cake after he finished the milk. The continuation of this is the fact that the CPU saves the state of the current process before switching between processes, and when it switches to this process again, it runs from the previously saved state (which also shows the cost of process switching).

Ii. creation of the process (Creation)2.1 Process creation time
    1. The process (boot) is created at system startup. This time is created by the system to run the necessary processes, and some to interact with the UI, some belong to the background process, such as the email acceptance process
    2. Created by the existing process by calling the system's create call. For example, in a Web system, you can create another Excel process to complete the data import into Excel function
    3. Created when a user initiates a request, such as when the user clicks the mouse and enters the command to respond to the user's request by creating the appropriate process
2.2 Creating a process

The above mentioned three ways to create a process are consistent in the way that the process was created: skipping a system call to complete the creation of a process by an existing process.

    1. Unix:fork
    2. Windows:createprocess

The system call tells the operating system to create a process.

The process that initiates the system call is the parent process, the process being created is a child process, the parent-child process is independent of each other, and their address space is completely different.

2.3 Hierarchical relationship of processes (Hierarchy)

As stated above, the new process is done through the call of the creation process, which is sent by the OS. The created process is called child process. This child process may also be able to create sub-processes again for the OS to request ..... And so on, there will be a process inheritance chain.

This process, which becomes a chain, exists in Unix as a group of processes. But in windows, these processes are actually completely independent. Inheritance relationships are not important in the process.

iii. Termination of the process (termination)

After a process is created, it terminates, and the process is terminated in a relatively good understanding of the following conditions:

    1. Normal termination: tells the operating system (System call) to terminate the process when the process finishes its own business
    2. Terminates when an error occurs. When a process discovers an error, such as a resource does not exist or the program that is running has a bug. such as being 0 apart.
    3. Kill by another process. For example, under Windows, you can kill the system directly through the task Manager.

In some operating systems, when a process terminates, the process in which it is created is also killed.

Iv. Status of the process (state)4.1 Status

After the process is created there are three states:

    1. Running (in operation)
    2. Blocked (blocked)
    3. Ready

Blocked refers to the process waiting for external stimuli (independent of the CPU), such as the console program, which has been waiting for user input.

Ready means that a process can run without waiting for any resources, but the CPU is consumed by other processes, without CPU resources

4.2 State Switching

running-"Blocked: The process requires additional external resources while it is running.

blocked-"Ready: The resources needed for the process are met

ready-"Running: determined by the CPU scheduler, the CPU can be used for the current process

running-"Ready: CPU Scheduler, CPU allocated to other processes (such as the above example, Dad stopped the cake to give his son hot milk, this time the cake is in the ready state)

Operating system-process (1)

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.