Process Control: Process creation, termination, blocking, waking, and switching

Source: Internet
Author: User
Tags terminates

Process Control: Process creation, termination, blocking, waking, and switching

The main function of process control is to implement effective management of all the processes in the system, which has the functions of creating new processes, undoing existing processes, and implementing process state transitions. In the operating system, the process is generally used to control the program segment is called the primitive language, the characteristics of the original language is not allowed to interrupt during execution, it is an inseparable basic unit.

Creation of processes

Allows one process to create another process. At this point the creator is called the parent process, and the process being created is called a child process. A child process can inherit resources owned by the parent process. When a child process is revoked, the resources it obtains from the parent process should be returned to the parent process. In addition, when you revoke a parent process, you must also revoke all of its child processes.

In the operating system, the end user login system, job scheduling, system service, application request of the user program will cause the process to be created. The process by which the operating system creates a new process is as follows (creating primitives):

    1. Assign a unique process identification number to the new process and request a blank PCB (PCB is limited). If the PCB application fails, the creation fails.
    2. Allocates resources for processes, allocates the necessary memory space (embodied in the PCB) for the program and data of the new process, and for the user stack. Note: If there is insufficient resources (such as memory space), this is not a failed creation, but rather a "waiting state", or "blocking state", waiting for the memory resource.
    3. Initialize the PCB, mainly including the initialization of the flag information, initialization of the processor state information and initialization of the processor control information, and set the priority of the process and so on.
    4. If the process-ready queue is able to accommodate the new process, it inserts the new process into the ready queue and waits for dispatch to run.
Termination of the process

The main events that cause the process to terminate are: The normal end, which indicates that the process's task is complete and ready to exit. The end of an exception is when a process is running, an exception event occurs that causes the program to fail to run, such as a storage area that is out of bounds, a protection error, an illegal instruction, a privileged command error, an I/O fault, and so on. External intervention means that the process terminates operations at the request of the outside world, such as operator or operating system intervention, parent process requests, and parent process termination.

The process by which the operating system terminates the process is as follows (undo primitive):

    1. Based on the identifier of the terminated process, the PCB is retrieved and the status of the process is read from.
    2. If the terminated process is in the execution state, the execution of the process is terminated immediately, and the processor resources are allocated to other processes.
    3. If the process also has child processes, all its child processes should be terminated.
    4. All resources owned by the process, either returned to its parent process or returned to the operating system.
    5. Remove the PCB from the queue (linked list).
Blocking and waking of processes

The executing process, because some expected events did not occur, such as requesting system resources failed, waiting for the completion of an operation, new data has not arrived or no new work to do, etc., the system automatically executes the blocking primitive (block), making itself from the running state into a blocking state. It can be seen that the blocking of a process is an active behavior of the process itself, and therefore it is possible to turn it into a blocking state only if the process is in a running state (acquiring the CPU).

The blocking primitives are executed as follows:

    1. Locate the PCB that corresponds to the identification number of the process that will be blocked.
    2. If the process is running, it will protect its site, turn its state into a blocking state, and stop running.
    3. Insert the PCB into the waiting queue for the corresponding event.


When an event is expected by a blocking process, such as when the I/O operation it initiated has completed or the data it expects to have arrived, the wake-up Primitive (Wakeup) is invoked by the process (i.e., the process that provided the data) to wake the processes waiting for the event.

The execution of the wake-up Primitives is:

    1. The PCB of the corresponding process is found in the wait queue for this event.
    2. Move it out of the wait queue and set its state to ready.
    3. Insert the PCB into the ready queue and wait for the scheduler to dispatch.


It is important to note that the block primitive and the wakeup primitive are pairs of primitives that have exactly the opposite effect and must be used as a pair. The block primitive is implemented by the blocking process self-invocation, while the wakeup primitive is implemented by a process called wake-up or other related processes.

Process switching

For a typical process, its creation, revocation, and I/O operations that are required to be done by the system device are entered into the kernel using system calls, which are then completed by the appropriate handlers in the kernel. Process switching is also implemented with the support of the kernel, so it can be said that any process running under the support of the operating system kernel is closely related to the kernel.

Process switching refers to the process in which the processor runs from one process to another, making a substantial change in the running environment of the process.

Process switching is as follows:

    1. Save the processor context, including program counters and other registers.
    2. Update PCB information.
    3. The PCB of the process is moved into the appropriate queue, such as ready, in an event blocking queue.
    4. Select another process to execute and update its PCB.
    5. Update the data structure of memory management.
    6. Restore the processing machine context.


Note that the process switch is different from the processor mode switch, and the processor may logically be running in the same process when the mode is switched. If the process goes into a kernel-state operation due to an interruption or an exception, and then returns to a program that has just been interrupted after execution, the operating system simply restores the CPU field that the process is saving to the core without changing the environment information of the current process. However, to switch processes, the current running process changes, and the environment information for the current process also needs to be changed.

Process Control: Process creation, termination, blocking, waking, and switching

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.