Computer Operating System Processes and threads

Source: Internet
Author: User
Communication between processes and thread processes in computer operating systems

L low-level Mode

N semaphores

N

L advanced mode

N shared storage system

N message transmission system

N pipeline Communication

Thread Communication Mode

L mutex lock

L condition variable

L count semaphores

L multi-read and single-write locks

 

Differences between process threads

A process is the unit in which resources are allocated by the system. Each process corresponds to an activeProgramWhen a process is activated, the operating system allocates system resources, including memory, I/O, and CPU, to it for execution.

A thread is the unit of CPU allocation time. Each thread corresponds to a function in the process, that is, in the memory.CodeWhen multiple threads are executed, the CPU allocates time based on their priorities to enable them to complete their functions.

Generally, a process consists of at least one thread, one main thread, and other threads. Multiple Threads aim to share the CPU time slice to complete parallel tasks.

The following are my own documents:

Comparison of threads and processes:

A thread is a basic unit that can run independently less than a process. Generally, a process has several threads and at least one thread is required.

    1. Scheduling: A thread is the basic unit of scheduling and scheduling, and a process is the basic unit of resource ownership.
    2. Concurrency: Concurrent execution can be performed between processes and between multiple threads in a process.
    3. Resources: A process is an independent unit that owns resources. A thread does not own system resources (or has a few resources) but can access the resources of its processes.
    4. System overhead: when a process is created or withdrawn, resources, such as memory space and I/O devices, must be allocated or recycled by the system, the overhead of the OS is significantly greater than the overhead when the thread is created or withdrawn; the overhead of process switching is much higher than the overhead of thread switching.

 

A process is an application running in the system. A thread is the basic unit for the system to allocate processor time resources, or a unit that is executed independently within the process. For the operating system, the scheduling unit is a thread. A process includes at least one thread, which is usually called as the main thread. A process starts from the execution of the main thread and creates one or more additional threads.

What is the difference between a process and a thread? A process is an instance of the execution program. For example, when you run the upload program (nodepad.exe, you create a code used to form notepad.exe and the process that needs to call the dynamic link library. Each process runs in a dedicated and protected address space. Therefore, if you run two copies of notepad at the same time, the data used by the program is independent of each other in the respective instances. The data opened by the second instance of the program cannot be seen in a copy of notepad.

The sandbox is used as an example to describe. A process is like a sandbox. The thread is like a child in the sandbox. The children ran around in the sandbox, and may drag the sand into the eyes of other children. They would kick each other or bite each other. However, the difference between these sandboxes is that each sandbox is completely composed of walls.

Close to the ceiling, no matter how hard the children in the box are, they will not affect other children in the sandbox. Therefore, each process is like a protected sandbox. No one can go in or out without permission.

In fact, the thread runs but the process does not run. The only way for two processes to obtain dedicated data or memory is to share the memory block through the Protocol. This is a collaboration policy. Next let's analyze the process tab in the task manager.

The process here refers to a series of processes that are identified by the executable program instances they run. This is why the ing name is given in the first column of the Process tab. Note that there is no process name column. A process does not have a ing name independent of the instance to which it belongs. In other words, if you run five Beibei, you will see five processes called notepad.exe. How are they different from each other? One way is through their process ID, because each process has its unique encoding. The process ID is generated by Windows NT or Windows 2000 and can be used cyclically. Therefore, process IDs will not be larger and larger, and they can be recycled. The third column is the percentage of CPU time occupied by the threads in the process. It is not the number of the CPU, but the percentage of CPU time occupied by the process. At this time, my system is basically idle. Although the system seems to use only a small amount of CPU time every second or so, the idle process of the system still consumes about 99% of the CPU time.

The fourth column shows the CPU time, which is the hour, minute, And seconds occupied by threads in the process. Please note that I use the word "Occupy" for threads in the process. This does not necessarily mean that it is the total CPU time consumed by the process, because, as we will see later, the NT timing method is that when a specific clock interval is triggered, no matter who happens to be in the current thread, it will be calculated within the CPU cycle. Generally, the clock runs at 10 milliseconds in most NT systems. The heart beats every 10 ms of NT. Some driver code snippets run and show who is the current thread. Let's keep the last 10 milliseconds of CPU time in its account. Therefore, if a thread starts to run and is finished after 8 ms of continuous running, then the second thread starts to run and lasts for 2 ms, the clock is triggered, please guess which thread the entire 10 ms clock cycle is recorded in? The answer is the second thread. Therefore, there are some inherent inaccuracies in NT, and NT timing is in this way. The actual situation is also true. In most 32-bit operating systems, there is an interval-Based Timing mechanism. Remember this, because sometimes when you observe the total CPU usage of a thread, it may appear although the thread may have been running for more than 100,000 times, however, the CPU usage may be zero or very short-lived, so the above explanation is the reason. The above is the basic information column we can see in the process tab of the task manager.

 

Kernel support thread

InKernelIt depends on the kernel, whether it is a thread in the user process or a thread in the system process. Here, a thread control block is set for each thread in the kernel space. The kernel perceives and controls the existence of the thread based on the control block.

User-level thread

This thread only exists in the user space. For such functions as thread creation, cancellation, and synchronization and communication between threads, no system call is required. User-level thread switching usually occurs between many threads of an application process. At this time, Kernel support is not required. Switching rules are simple and fast.

It is worth noting that for a user-level thread system, scheduling is based on processes. So rotation scheduling is adopted.AlgorithmEach process executes a time slice in turn. This seems fair to all processes, but it is not. One process A has a user-level thread, and another process B has 100 threads. Therefore, the running time of the thread in process a is 100 times the running time of each thread in process B.

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.