📜  操作系统-进程

📅  最后修改于: 2020-12-13 15:39:35             🧑  作者: Mango


处理

进程基本上是正在执行的程序。流程的执行必须按顺序进行。

流程定义为一个实体,它表示要在系统中实现的基本工作单元。

简而言之,我们将计算机程序编写在一个文本文件中,当我们执行该程序时,它成为执行程序中提到的所有任务的过程。

当程序被加载到内存中并成为一个进程时,它可以分为四个部分:堆栈,堆,文本和数据。下图显示了主内存中进程的简化布局-

工艺组件

S.N. Component & Description
1

Stack

The process Stack contains the temporary data such as method/function parameters, return address and local variables.

2

Heap

This is dynamically allocated memory to a process during its run time.

3

Text

This includes the current activity represented by the value of Program Counter and the contents of the processor’s registers.

4

Data

This section contains the global and static variables.

程序

程序是一段代码,可以是一行或几百万行。计算机程序通常由计算机程序员以编程语言编写。例如,这是一个用C编程语言编写的简单程序-

#include 

int main() {
   printf("Hello, World! \n");
   return 0;
}

计算机程序是指令的集合,这些指令在由计算机执行时执行特定的任务。当我们将程序与流程进行比较时,我们可以得出结论,流程是计算机程序的动态实例。

执行明确定义的任务的计算机程序的一部分称为算法。计算机程序,库和相关数据的集合称为软件

工艺生命周期

当一个进程执行时,它会经过不同的状态。在不同的操作系统中,这些阶段可能有所不同,并且这些状态的名称也未标准化。

通常,一个进程一次可以具有以下五个状态之一。

S.N. State & Description
1

Start

This is the initial state when a process is first started/created.

2

Ready

The process is waiting to be assigned to a processor. Ready processes are waiting to have the processor allocated to them by the operating system so that they can run. Process may come into this state after Start state or while running it by but interrupted by the scheduler to assign CPU to some other process.

3

Running

Once the process has been assigned to a processor by the OS scheduler, the process state is set to running and the processor executes its instructions.

4

Waiting

Process moves into the waiting state if it needs to wait for a resource, such as waiting for user input, or waiting for a file to become available.

5

Terminated or Exit

Once the process finishes its execution, or it is terminated by the operating system, it is moved to the terminated state where it waits to be removed from main memory.

流程状态

过程控制块(PCB)

流程控制块是操作系统为每个流程维护的数据结构。 PCB由整数进程ID(PID)标识。 PCB保留了跟踪下表中列出的过程所需的所有信息-

S.N. Information & Description
1

Process State

The current state of the process i.e., whether it is ready, running, waiting, or whatever.

2

Process privileges

This is required to allow/disallow access to system resources.

3

Process ID

Unique identification for each of the process in the operating system.

4

Pointer

A pointer to parent process.

5

Program Counter

Program Counter is a pointer to the address of the next instruction to be executed for this process.

6

CPU registers

Various CPU registers where process need to be stored for execution for running state.

7

CPU Scheduling Information

Process priority and other scheduling information which is required to schedule the process.

8

Memory management information

This includes the information of page table, memory limits, Segment table depending on memory used by the operating system.

9

Accounting information

This includes the amount of CPU used for process execution, time limits, execution ID etc.

10

IO status information

This includes a list of I/O devices allocated to the process.

PCB的体系结构完全取决于操作系统,并且在不同的操作系统中可能包含不同的信息。这是PCB的简化图-

过程控制块

PCB在整个生命周期中都会得到维护,并且在过程终止后将其删除。