CS ten days to learn the operating system - process management 01

Process Management 01

The concept of process

Computer process is a very important concept in the entire history of computer development, the evolution of the operating mechanism of the operating system program sequence can be divided into:

  1. Uniprogramming: generally refers to a time or number of each program (job) is loaded from disk into memory, CPU must wait for I / O completion can be performed before, CPU utilization rate.
  2. Multiprogramming: a plurality of jobs transferred talk automatic memory after treatment, but uniprogramming and no interactive multiprogramming, poor controllability
  3. Process: the PCB + program (described state period) + datasets
  4. Thread

Single channel -> Multi-channel system

Evolved from single-channel multi-channel program is a program with high-speed I / O, the low-speed CPU has a significant contradiction, so the introduction of the solution as multiprogramming. As an example, a single channel program, if I / O is not completed, then the CPU has been idle. However, in multi-channel program, a program at the time when the CPU occupancy, remaining program may start with the I / O request, without disturbing each other, thus reducing idle I / O of the CPU. When a program is released CPU, the next program continue to occupy CPU.

In the multi-channel program, there is often such a case, for example, a program needs to monitor the input value, then the program will delegate the I / O system to the value, then the value before the completion of the program does not need to take up CPU , then the program will at this time by the CPU sequentially assigned a sequence queue because I / O CPU obstructive give up, and into the execution queue tail.

Multi-channel program states:
avatar

Scheduler multiprogramming
avatar

Multiprogramming -> Process

Adding some process is described in the program state in the program block (PCB)

Evolution is a process from the process of multi-channel program by increasing the concurrency to further improve CPU utilization. In fact, the scheduling mechanism is multiprogramming rigid and flexible in other sequential control program for execution. Realize the function is to monitor the PCB.

Status of the process:
avatar

Process Scheduling:
avatar

Process -> Thread

在进程之下,我们引入了线程。在说线程之前,我们引入那么一个问题,假定你制作了一个即时通讯的程序,如果你只是用一个进程去控制程序运行,会发生什么?事实上这里发生的事情你有时候可以在一些小厂商做出的低劣游戏中发现这一问题。我们在有些制作不好、历史久远或者代码质量差的游戏中,经常能发现,一旦网卡了,整个游戏甚至都会卡顿甚至无响应,游戏的渲染也受到了很大的影响。有时候是因为网络一直在尝试发包导致,但是更多时候是因为进程调度问题。可是为什么网络是基于外部的,却可以影响内部的引擎渲染之类的功能呢?原因就是我们之前讲过,请求网络是一个明显的I/O过程,假设网络不好,那么我们的程序一直处于I/O阻塞的状态下,从而放弃CPU,那么我们渲染的代码也会迟迟得不到运行。会到我们之前的问题,假设你只是用一个进程去制作了即时通讯软件,一旦网络丢包之类的网络故障发生时,你的程序很容易卡顿。

说了那么多,我们应该如何去解决这个问题?很自然的我们会想到使用多进程去制作一个软件,那么其中一个进程发生阻塞的时候,我们其余的进程会继续占用CPU,则整体运行并不会受太大影响。但是这种方法需要占用大量的时空,因为进程的调度是依赖PCB以及PCB的监控程序,进程切换过程中,上下文切换也会导致PCB状态切换,需要花费大量的时间进行查询、修改等操作,并且内存栈的使用也会过于频繁导致空间消耗,并且在操作系统中,PCB的数量是有限的,因此使用多进程并不是一个号的方法。

这里我们就引出多线程的方法,进程就成为了线程的一个容器,且进程和线程可以同时存在,线程几乎不占用多少空间,整体也比进程小的多,那么对线程的调度开销就会远比进程小得多。进程的数量也减少了,那么整体系统的压力也小了。

进程和程序的区别

  1. 程序是一段代码编译后的产物,在执行过程中被拷贝至内存,通常是静态不变的,进程在运行过程中是会发生状态转变,通常认为是动态的。进程是对程序一次执行的过程。
  2. Procedures and processes are many relationships, for example, while performing two different programs and operating system GUI graphics rendering relations with various visualization programs. You can find these relationships in the Task Manager

Process features

  1. Concurrency: concurrent consistent with the OS
  2. Asynchronous: the OS consistent with asynchronous
  3. Dynamics: process during operation will state transition occurs, it is usually considered to be dynamic.
  4. Structural: PCB using compositions
  5. Independence: In the resource allocation process, each process is independent of distribution. For example, the position of each process in memory is independent.

The composition process

Typically we only consider the PCB or the PCB + + program instruction section + data section. Here's what it comes to instruction and data segments is it?

Operation instruction segment is a specific logic, and the data segment is stored in the specific data value, they are usually stored on the stack. For example, a piece of code:

public int Add()
{
    return 3+4;
}

This code is stored in the process function pointer, i.e. the specific point in the program memory; 3 and 4 as the data will be stored in a separate section of the stack, and the '+' is stored in the instruction section.

PCB composition

  1. Uniquely identifies the process: PID
  2. A process whereby five states: state
  3. Priority: to perform sequential control process

Composition instruction segments

  1. Operating Address: program code means in the memory location
  2. External memory address: location of the program on the storage device
  3. Code segment pointer: the specific location of the program instruction segments in memory
  4. Enter the memory time: enter the time

Data segments

  1. Stack pointer: address for storing data
  2. Data segment pointers: the address of the code data segment

The composition process
avatar

Process Operation Analysis

For a process or program needs to be run, the following three things are essential:

  • PCB
  • RAM
  • CPU

Status of the process:
avatar

  • For New -> Ready process, the process will apply to the operating system memory and PCB, while queued makes this process very simple.
  • Ready -> Run process, the operating system needs to allocate CPU resources to the process of making the program running. In turn, it is because for some reason makes the process not take up CPU, usually the time slice runs out.
  • Run -> blocking process, usually with an I / O request block the process leading to the interruption.
  • Blocked -> Ready process is renewed after the process I / O completion, the process to re-enter the ready queue
  • Run -> complete memory is returned and remove PCB.

When state transition usually is to implement the following three steps:

  • Distribution (application) memory or CPU
  • Recover
  • Modify PCB

If my article help you, please give me a triple and a star.

Github

BiliBili Home

WarrenRyan'sBlog

Blog Park

Guess you like

Origin www.cnblogs.com/WarrenRyan/p/12364646.html