Differences and connections between programs, processes, and threads

Source: Internet
Author: User
Article Title: Differences and connections between programs, processes, and threads. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

Definition:

A program is just an ordered set of commands,

A second process is a running activity of a program with certain independent functions on a dataset. It is an independent unit for the system to allocate and schedule resources;

A three-thread is an entity of a process and the basic unit of CPU scheduling and dispatching. It is a smaller basic unit that can run independently than a process. the thread itself basically does not have system resources, and only has a few resources (such as program counters, a set of registers and stacks) that are essential for running ), one thread can create and withdraw another thread;

1. Difference and connection between processes and threads

(1) division scale: the thread is smaller, so the concurrency of multi-threaded programs is higher;

(2) resource allocation: A process is the basic unit of resource allocation. Multiple Threads in a process share their resources;

(3) Address Space: The process has an independent address space, and multiple threads in the same process share their resources;

(4) Processor Scheduling: A thread is the basic unit of processor scheduling;

(5) Execution: Each thread has an entry for running the program, a sequence of execution and the exit of the program. However, the thread cannot be executed independently and must be a process. A process must have at least one main thread. In short, a program has at least one process, and a process has at least one thread.

Difference and connection between processes and programs

(1) A program is only an ordered set of commands. It does not have any running meaning. It is just a static entity. The process is different. It is the execution of a program on a certain dataset. A process is a dynamic entity that has its own lifecycle. It reflects all the dynamic processes of a program running on a certain dataset.

(2) processes and programs do not correspond one by one. A program runs on different datasets and becomes different processes. process control blocks can be used to uniquely identify each process. This is exactly what the program cannot do. Because the program has no direct connection with the data, the set of their commands is still the same even if different data programs are executed, therefore, it is impossible to identify the programs running on different datasets. Generally, a process must have a corresponding program and only one program. A program may not have a corresponding process (because it is not executed) or multiple processes (running on several different datasets ).

(3) The process is also concurrent and interactive, which is different from the closed process.

Process and program differences and contact lists are as follows:

1) a program is only an ordered set of commands. It does not have any running meaning. It is just a static entity. The process is different. It is the execution of a program on a certain dataset.

A process is a dynamic entity that has its own lifecycle. It is created and runs due to scheduling. It is in the waiting status due to waiting for resources or events and canceled due to task completion. It reflects all the dynamic processes of a program running on a certain dataset.

2) processes and programs do not correspond one by one. A program runs on different datasets and becomes different processes. process control blocks can be used to uniquely identify each process. This is exactly what the program cannot do. Because the program has no direct connection with the data, the set of their commands is still the same even if different data programs are executed, therefore, it is impossible to identify the programs running on different datasets. Generally, a process must have a corresponding program and only one program. A program may not have a corresponding process (because it is not executed) or multiple processes (running on several different datasets ).

3) The process is also concurrent and interactive, which is different from the closed process. Processes and threads are the basic units for running programs that the operating system understands. The system uses this basic unit to realize the system's concurrency for applications. The difference between a process and a thread is:

In short, a program has at least one process, and a process has at least one thread.

The thread division scale is smaller than the process, making the multi-thread program highly concurrent.

In addition, the process has independent memory units during execution, and multiple threads share the memory, which greatly improves the program running efficiency.

The execution process of a thread is different from that of a process. Each Independent thread has a program running entry, sequence execution sequence, and program exit. But the thread cannot be executed independently. It must exist in the application and the application provides multiple thread execution control.

Logically, multithreading means that multiple execution parts in an application can be executed simultaneously. However, the operating system does not view multiple threads as multiple independent applications to implement process scheduling, management, and resource allocation. This is an important difference between processes and threads.

A process is a running activity of a program with certain independent functions. A process is an independent unit for the system to allocate and schedule resources.

A thread is an entity of a process. It is the basic unit for CPU scheduling and scheduling. It is smaller than a process and can run independently. the thread itself basically does not have system resources, and only has a few resources (such as program counters, a set of registers and stacks) that are essential for running ), however, it can share all resources of a process with other threads of the same process.

One thread can create and cancel another thread, and multiple threads in the same process can be concurrently executed.

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.