Operating System Process

Source: Internet
Author: User

A process is an instance of a program being executed. It includes the current value of the program counter, register, and variable. In a single-CPU environment, processes run alternately, And the CPU switches between multiple processes quickly. This makes it feel that multiple processes are running at the same time, but only one process is running at the same time, this is the so-called pseudo-parallel.
There are four ways to create a process:
    1. System initialization: when the operating system starts, some processes, including foreground and background processes (Daemon), will be created ).
    2. Running Process Execution System Call: one process sends a system call to create another process, so that multiple processes can complete the task together.
    3. User request to create a process: This is a method we are most familiar. In the command line environment, type a command, and double-click the icon in the graphic interface environment to create a new process.
    4. Initialization of a batch job: when the operating system deems that there are resources to run another job, it creates a new process.
The above four methods are used to create a process. In essence, a process executes a system call for creating a process. For example, in a UNIX system, a combination of fork + exec is used to generate a new process.
The conditions for terminating a process include the following:
    1. Normal Exit: After the process completes the task, the execution system call Exits normally, for example, the exit system call of the UNIX system.
    2. Errors discovered by the process: for example, the file to be opened by the program does not exist.
    3. Errors Caused by processes: for example, access to illegal addresses, Division of 0, and other errors caused by the program itself.
    4. Killed by other processes: other processes terminate the current process through system calls, such as kill system calls of UNIX systems.

A process has three states:
    1. Running status: CPU usage.
    2. Ready State: it can run, but it is paused because other processes occupy the CPU.
    3. Blocking Mode: stop waiting for an external event, such as disk I/O.
The relationship between the three States is as follows:

It should be noted that when a blocking process waits for an event, it cannot be run directly, but it must be ready. If the CPU is idle at this time, you can directly run the process; otherwise, you must wait for the scheduling of the scheduler.
The operating system maintenance for Process implementation has a table (represented as an array of structures in the Program), which is called a process table. Each process corresponds to a table item (Process Control Block), which contains information about the process. The process needs to use the information in table items when switching between different States. For example, when a process switches from the running state to the blocking or ready state, the information of the process must be saved in its corresponding table items. After the process resumes running, you need to retrieve the information from the table items and continue the execution. This allows the process to give people the illusion of continuous execution, in fact, it is interrupted. The table items are roughly as follows:

Reference: Modern OS P47-P52.

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.