Process Management 1, Process Manager

Source: Internet
Author: User

Process Management 1, Process Manager

From the perspective of processes, operating systems are considered to be composed of several independent programs and a core (kernel) that can coordinate and control these programs.

These running programs are called processes. They are the basic units for resource allocation and independent operation. Each process completes a specific task. The operating system kernel must control and coordinate the running of these processes, solve the communication between processes, and realize the communication between concurrent processes from the point where the system can work concurrently, and solve the competition for shared resources.

Address:Http://www.cnblogs.com/archimedes/p/os-process-management1.html, Reprinted, please specify the source address.

1. Diagram of the basic concepts of processes:

Definition: A directed acyclic graph is a binary group consisting of a collection of nodes and directed edges. Where:

Node: indicates a statement, a program segment, or a process directed edge: The frontend relationship between two nodes ""

(→={ (Pi, Pj) | Pi must be completed before Pj starts execution }).

Direct frontend and direct successor

Initial node and termination Node

Program Execution in sequence

Generally, a program can be divided into several program segments, which must be executed in a certain order. Only the current operation can be executed before subsequent operations can be performed.

 

Eg2: Computing: I: input operation C: computing operation P: print operation during computing, the user's program and data are always input first and then calculated, finally, print the result.

The program has the following features During sequential execution:

Sequence-the operation of the processor is executed strictly in the sequence specified by the program. each operation must end before the next operation starts.

Closed-execution in a closed environment exclusive to the full-Host resources, and execution results are not affected by the outside world.

Reproducibility-as long as the environment for executing the program is the same as the initial conditions, when the program is executed repeatedly, whether it is executed from start to end without stopping, or "Stop and stop, will get the same results.

Concurrent program execution when processing a batch of jobs, some programs can implement the feature intermittent-Mutual constraints during concurrent execution, which leads to the intermittent activity pattern of "execution-pause-execution" of concurrent programs. Lost closeness-multiple programs share various resources in the system, and the resource status is changed by multiple programs. Non-reproducibility-concurrent execution of a program breaks the closeness of the system resources exclusively occupied by another program, thus undermining reproducibility. Process Definition and features

1. process Definition

1) A process is an execution of a program.

2) A process is an activity that occurs when a program and its data are executed sequentially on the processing machine.

3) A process is a program running on a dataset. It is an independent unit for system resource allocation and scheduling.

Main differences between processes and programs:
  • A program is an ordered set of commands. It does not have any running meaning. It is a static concept. A process is an execution process of a program on the processing machine. It is a dynamic concept.
  • The existence of programs is permanent. A process has a life cycle. It is created and executed due to scheduling. It is suspended due to lack of resources and disappears due to cancellation.
  • A program is only an ordered set of commands. A process consists of a program segment, a related data segment, and a process control block (PCB.
  • There is no one-to-one correspondence between processes and programs.
 

Program

Process

Concept

Static

Dynamic

Storage

External Store

Memory

Time of occurrence

Permanent

Life Cycle

Composition

Ordered commands

Program segment, data segment, PCB

Correspondence

One program can correspond to multiple processes

A process can correspond to multiple programs

Process Features

Basic Features of a process:

(1) Structural Features

Each process should be configured with a PCB to describe and record the process of motion changes and make them run correctly. Therefore, in terms of structure, each process (process entity) is composed of a program segment, related data segment, and process control block (PCB.

Note: In earlier UNIX versions, the three components of a process are process images"

(2) Dynamic

The essence of a process is the execution process of a program on the processing machine, so it is dynamic. Therefore, dynamic nature is the most basic feature of a process. At the same time, the dynamic nature is also manifested in that a process has a life cycle. It is created and executed due to scheduling. Execution is paused due to lack of resources, and execution is extinct due to cancellation.

(3) concurrency

Multiple Process entities exist in the memory at the same time and can run simultaneously within a period of time.

The purpose of introducing a process is to enable concurrent execution of the process to improve resource utilization. Concurrency is an important feature of the process and an important feature of the OS.

(4) Independence

A process is a basic unit for independent operation and an independent unit for system resource allocation and scheduling.

(5) Asynchronization

It refers to the process moving forward at an independent and unpredictable speed.

Process status

To portray the entire process, you can divide the lifecycle of a process into a group of states:

1. Five States of a process (two transient states and three basic states) new creation/creation: the process is being created. The State terminated is terminated, withdrawn, and exited. The process is completed, the status of resources occupied by the release. Ready-ready: the process has all resources except the processor, waiting for the distribution of the processor to execute. Running-run/execute: The status when a process obtains the necessary resources and is processing the execution on the machine. Waiting-waiting/blocking: the process being executed cannot be executed because of an event.

A process is not always in a certain state during running, but is constantly switching from one state to another.

2. Process status transition

3. Process Suspension

In some systems, to better manage and schedule processes, the suspension status is introduced:

Pending/static status:

During the running of a program, the process is often paused to meet certain needs. This static state is called the pending state of the process.

Reasons for introducing the pending status:

  • Requirements of end users: When an end user finds a problem while running the program, the user must suspend the running process and put the process in the suspended state.
  • Parent process needs: in order to check and modify a child process or coordinate activities between child processes, the child process must be suspended.
  • Operating system requirements: the operating system suspends some processes in order to check the resource usage or make accounting.
  • Swap needs: in order to improve the memory utilization, some processes in the memory are suspended to be transferred to other programs.
  • Load Adjustment needs: due to heavy workload, some unimportant processes are suspended to ensure the normal operation of the system (real-time operating system)

After the pending state is introduced, the switching between the suspended state (static state) and the non-suspended state (active State) is increased ,:

Process Control Block

Process control block PCB

It is a data structure defined by the operating system for each process to manage and control the running of processes. It records all the information required by the system to manage processes. The system perceives the existence of a process based on the PCB. PCB is the only identifier of the process. Example: PCB in Linux

1. Function of process control block PCB

It is the basis for the operating system to control and manage concurrent processes. It is also the basis for the system to perceive the existence of processes, that is, PCB is the only sign of the existence of processes.

2. Process Control Block PCB Information

Depending on the operating system requirements, the information contained in the PCB is somewhat different, but usually includes the following information:

(1) process identifier:
Internal identifier (the unique identifier assigned to a process when a process is created by the system, usually an integer called a process number, used to distinguish different processes)
External identifier (consisting of letters and numbers, used when a user accesses the process ).

(2) processor status (breakpoint information ):
It is the content of various registers (General registers, PCs, psws, etc.) in the processor.

(3) process scheduling:
Records Information about process scheduling (such as status, priority, and event ).

(4) Process Control:
Records the process control information (address, synchronization mechanism, resource list, and link pointer of programs and data) of the system)

3. Process Control Block PCB Organization

In a system, there are usually many processes in different States. To facilitate process scheduling and management, you need to organize the PCB of each process in an appropriate way. Common Organization methods are as follows:

Link mode: link the PCB in the same state into a queue, forming a ready queue, blocking queue, etc.

Indexing Method: Process in the same State is organized in an index table. The index table items point to the corresponding PCB. different statuses correspond to different index tables. Process Control

Process control is the most basic function in process management, that is, to effectively manage all processes in the system. Its functions include:

  • Process Creation
  • Process Revocation
  • Process blocking and wakeup, etc,

These functions are generally completed by the operating system kernel.

Process Creation

A process can create several new processes, and a new process can create sub-processes. to describe the relationship between processes, a process diagram is introduced, as shown in :)

1. Process Diagram: A process tree or process family tree is a directed tree that describes the relationship between process families.

2. Events that cause Process Creation

In a multi-program environment, only processes can run in the system. To make a program run, you must create a process for it. Events that cause process creation include:

User Logon: In a time-sharing OS, if the user type a logon command on the terminal and the user is a legal user, the system creates a process for the terminal and inserts the ready queue.

Job Scheduling: in the batch processing OS, when a job is scheduled into memory according to an algorithm, the system allocates necessary resources for the job, creates a process for the job, and inserts a ready queue.

Provide services: if a user needs a service while the program is running, the system creates a process to provide services for the user and inserts the ready queue.

Application Request: In the running process, you need to create a process and insert the ready queue.

3. Process Creation

Once the operating system discovers an event that requires process creation, it calls the Process Creation primitive create () to create a new process according to the following process:

Process Revocation

After a process completes its tasks, it should be abolished to release all types of resources it occupies in a timely manner.

1. Events that cause process Revocation

  • Process ends normally
  • Process ended unexpectedly
  • External intervention

If an event in the system requires that the process be undone, the OS calls the Undo primitive to undo the process.

2. Two revocation policies can be used for the Undo primitive.

Only detaches a specified process

Undo a specified process and all its child Processes

Process revocation process:

Process congestion and wake-up

When a process does not expect an event, the process calls the blocking primitive block () to block itself;

Block () function: changes the process from execution to blocking.

For a process in the blocking status, when an event is expected by the process, other related processes call the wake-up primitive wakeup () to wake up the blocked process and make it ready;

Wakeup () function: changes the process from blocking to ready.

1. Events that cause process blocking and Wakeup

  • Request System Service
  • Start an operation
  • New data has not arrived
  • No new work to do

2. Process Blocking

3. Process wake-up process

Process suspension and Activation

When a process suspension event occurs, the system will use the suspension primitive suspend () to suspend a specified process or a blocked process. When an event of an activation process occurs, the system uses the activation primitive active () to activate the specified process.

Process suspension process:

Process activation process:

Reference: China East University of Science and Technology Operating System

 


Process Management

Design ideas:
Define struct to represent Process Control Blocks
Function Description:
AddProcess (): to add a process

Sort (): sort by priority and arrival time

Print (): print

Attemper (): Scheduling

Code:
# Include "stdio. h"

# Include <windows. h>

# Define Time int

# Deprecision Max 100

Typedef struct process

{

Char name [10]; // process name

Int priority;

Time ReachTime; // Time of Arrival

Time NeedTime; // Time Required

Time UsedTime; // used Time

Char state; // status

} PCB; // Process Control Block

Int n; // indicates the total number of processes.

PCB pcb [Max];

Int pTime; // time slice size

Void AddProcess ()

{

Char ch;

Do {

System ("cls ");

Printf ("n enter the process name ");

Scanf ("% s", pcb [n]. name );

Printf ("Enter the priority of the process (0-10 )");

Scanf ("% d", & pcb [n]. priority );

Printf ("Enter the time required by the process ");

Scanf ("% d", & pcb [n]. NeedTime );

Pcb [n]. ReachTime = n;

Pcb [n]. UsedTime = 0;

Pcb [n]. state = 'W ';

N ++;

Do

{

System ("cls ");

Printf ("do you want to add more processes? (Y), no (N )");

Ch = getche ();

} While (ch! = 'Y' & ch! = 'N' & ch! = 'Y' & ch! = 'N ');

} While (ch = 'y' | ch = 'y ');

}

// Sorting function, which puts the first running process first, that is, pcb [0]

Void sort ()

{// Sort by bubble

Int I, j;

PCB temp;

// Sort by arrival time first

For (I = 0; I <n-1; I ++)

{

For (j = n-2; j> = I; j --)

{

... The remaining full text>
 
1. How can I manage processes? What can I do through process management?

Process Management is nothing fun. Generally, you can check that the computer currently uses a large number of resources, and you can simply check whether there are any problems in the system, such as whether there are programs that can be set, however, many Trojans and viruses cannot be seen in process management. So process management is nothing fun!

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.