The computer must know that the process processes and threads thread processes are defined as instances of a running program

Source: Internet
Author: User process and thread this concept of understanding is also very difficult, so far on the network can be found on the understanding of the data are very large, in different operating systems, such as Linux and Windows, the concept and implementation are not the same. Therefore, I am here to combine my own understanding of these two concepts, is about the general concept, and mainly based on Windows.

Typically, a process is defined as an instance of a running program. Each of the items that we see in the task manager can be understood as a process in which each process has an address space, which has the code and data for the executable in the address space, as well as the thread stack. A program has at least one process. A process can create child processes that can be created to work with the parent process or run independently.

The thread is subordinate to the process, that is, the thread cannot exist alone, and the thread exists in the process. Each process has at least one main thread, and the threads in the process are responsible for executing the code in the process, which is also called the "inertia" of the process. The resource used by the thread is the resource of the process to which it belongs. Threads also have their own resources, the main components are some of the necessary counters and line stacks, the use of small resources. We can understand that a process is a container, and a thread is a real work. Threads can be implemented in kernel space, or in user space.

In particular, Linux, in Linux, each process must have a parent process (if there is no parent process, the pid=1 root process as its parent process). The process exits, it becomes a zombie process, waiting for the parent process to exit the signal, if the parent process does not send him a signal, you have to find a parent process, or wait for the kernel to automatically destroy. The Linux kernel only provides support for lightweight processes, limiting the implementation of a more efficient threading model, but Linux focuses on optimizing the scheduling overhead of the process, making the Linux process switching overhead less expensive. So the Linux system does not have a real sense of threading mechanism. Linux, Linux threads are implemented through processes, and processes and threads are at the same level. (I'm referring to the Linux 2.6 kernel, which, in the latest Linux, optimizes the implementation of threads, but is still process-based.) Some Linux implements a new threading mechanism, but the mainstream is the same as I described)

The process has an independent memory unit during execution, and multiple threads share memory, which greatly improves the efficiency of the program operation. From a logical point of view, the meaning of multithreading is that in an application, multiple execution parts can be executed concurrently. However, the operating system does not consider multiple threads as separate applications to implement scheduling and management of processes and resource allocation. This is also a significant difference between processes and threads.

For example, the Explorer in Windows is the Resource manager process, and the process creates a thread every window we open. With the above description, we can know that the process has a separate address space, multi-process programs are more robust than multithreaded programs, but in the process of switching, the cost of large resources, less efficient.

In the first section, I mentioned, "Concurrency!" = Multithreading ", yes. such as the UNIX operating system and the Windows operating system support multi-user, multi-process concurrent execution, while the Java language supports the execution of multiple threads within the application process concurrently. We know that PHP does not have the concept of multi-threading in syntax, and how the Java/net multithreading is implemented. In fact, Java only uses the native method to invoke the operating system API to create multithreading. In addition, we often say how much of a website concurrency, Nginx is high concurrent server. Concurrency here is different from the concurrency concept I have in front of me. To achieve high concurrency, in addition to multithreading and other implementations, but also need a variety of good IO mechanism, or thread no more useless, resource utilization can not come up. High concurrency is implicated in synchronous and asynchronous IO multiplexing mechanisms.

The following is a list of some concepts in processes and threads.

    • Process: Create, destroy, create sub-process (fork), priority.
    • Threads: Create, suspend, resume, destroy, toggle, collaborate, sleep, wake up, wait, sync, lock, priority.

From the above description, you can basically clarify the relationship between the process and the thread. Finally, we summarize the following:

    1. Linux does not have multi-threaded implementations on the kernel, but it cannot say that Linux does not have multiple threads. Windows has a multithreaded implementation of the kernel.
    2. The process overhead is high and the thread overhead is small, but the process and thread overhead of Linux is not significantly different.
    3. Parallel implementation is inseparable from multithreading.

To leave a suspense, multi-threaded implementation and operation will also involve synchronous asynchronous, atomic and other concepts. These concepts intersect each other and do not go into the first place.

The computer must know that the process processes and threads thread processes are defined as instances of a running program

Related Article

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: 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.