A text to understand the operating system processes and threads ---

Processes and threads

 

process:

 

Baidu Encyclopedia of the definition:   process (Process) is a computer program on the activities run on a data set, the system is the basic unit of resource allocation and scheduling, is the underlying operating system architecture. In the computer architecture for the early design process, the basic process is the execution of the program entity; in contemporary computer architecture design for the thread, the thread is the process vessel. Program is instruction, organization of data and its description of the process is a solid program.

Personal understanding: the process is an instance of time can be complicated program execution. From the kernel's point of view, the purpose of the process is the basic unit of resource allocation and scheduling system (CPU time, memory, etc.)

 

Thread:

Defined Baidu Encyclopedia:   Thread (thread) is an operating system capable of operation scheduled minimum unit. It is included in the process of being, it is the process of the actual operation of the unit. A thread refers to a process in a single sequential flow of control, a process multiple threads concurrently, each thread in parallel to perform different tasks.

Personal understanding:       A thread is a physical process, is the basic unit of the system processor time allocation of resources, it is the smallest unit of program execution.

 

Process VS threads:

The actual operating system is running threads, processes only a container.

A thread is the smallest unit of the operating system running scheduling.

Included in the process, the process is actually running the unit work.

A process can be complicated by multiple threads, each performing different tasks.

 

 

process

Thread

Resources

The basic unit of resource allocation

Do not have the resources

Dispatch

The basic unit independent scheduling

The minimum unit of scheduled separately

Overhead

Process large overhead

Thread a small system overhead

communication

IPC process

Agree to read and write process data communication

Note: refers to the dissemination or exchange of information between different processes. It is a set of programming interfaces that allow programmers to coordinate the different processes, so that it can run on an operating system, and passed each other and exchange information.

IPC manner typically a duct (the PIPE) (named pipes including pipes and unnamed), message queues, semaphores, shared memory, sockets (Socket), Streams, semaphore and the like. Streams Socket and which support the process of IPC on two different hosts.

 

The difference between threads and processes can be categorized into the following four points:

1) address space and other resources: are independent processes, among threads of the same process of sharing. Threads within a process is not visible in the other process.

2) Communication: interprocess communication IPC, the threads can directly read and write process data segment (such as global variables) to communicate

------ processes and mutually exclusive needs assistance, to ensure data consistency.

3) scheduling and switching: thread context switching is much faster than the process context switch.

4) In a multithreaded OS, the process is not an executable entity.

 

Detailed process:   

The figure is the Task Manager process (by this figure we can more easily understand the process)

Process control is typically blocks (PCB) composed of a program, data and processes.

  1. PCB: PCB is the only existing process flag; generic data structure for description of the operation and control processes; all current state and the information recording process control operation processes; such processes are the basic unit of the PCB capable of independent operation.
  2. Program: Program section describes the process required to complete the function
  3. Data: required for program execution, including the data portion of the data and the work area.

 

The PCB (Program Control Block) The process aspect :( main memory)

Identifier: a unique identifier mark a process for distinguishing other processes.

Status: process status mark process, such as running state, blocking state.

Program counter: address of the next instruction to be executed process.

Memory pointers: code, process data associated pointer.

Contextual data: data stored in the processor when the process execution.

IO status information: a list of processes to be occupied by the file IO operations

Billing information: the use of processor time, the sum of the number of clocks and the like.

The above points can be summarized as: a process identifier, the processor status, process scheduling information, process control information.

 

Three-state process model

Three basic states: running, ready and blocking

Run: When a process running on a processor when the process is said to be running.

Obstructive: obstruction also to wait or sleep state, a process is waiting for a certain thing happen (such as requests I / O completion, etc.).

Ready: a process to get all the resources except for the processor, Once processor to run.

 

Five-state model

 

Threads explained

进程想要执行任务就需要依赖线程,一个进程至少有一个线程

 

多线程:想要理解多线程,先知道串行和并行

串行:所谓的串行就是按照一定的顺序去进行的,如下图所示,当任务A没有完成时,任务B没办法执行

 

 

并行:可以同时进程多个任务,如下图

那究竟什么是多线程呢

 

我们拿一个安全软件来举个例子哦,如果说开启这个软件,即我们创建了一个进程,

但是如果是单线程的话,那么我们这个杀毒软件在杀毒的时候就不能边清理垃圾。

但是如果是多线程的话,可以边杀毒,边清理垃圾等等,这个是严格意义上的同一时刻发生的,没有执行的先后顺序。

Guess you like

Origin www.cnblogs.com/waibizi/p/11229206.html