Python---Basic Knowledge Review (10) Processes and Threads

Foreplay: Concepts of Processes and Threads

If you have studied processes, threads, signals under linux, you will have a deeper understanding. So it is recommended to learn, including network programming, you can learn more, especially for select, pool, epool will have more understanding.

A process is the smallest unit of resource management, and a thread is the smallest unit of program execution. A program can have multiple processes, and a process can have multiple threads executing simultaneously

1. Process:

The operating system isolates the address space that individual processes can access. If information needs to be passed between processes. Then you can use inter-process communication or other methods, like signals, like files, databases, clipboards....etc. In process scheduling, there are many events required for process switching. In order to better support information sharing and reduce switching overhead. Threads are thus evolved from processes.

2. Thread:

A thread is the execution unit of a process. For most programs there may be only one main thread, the program process. In the system, it seems that all threads are executed at the same time. In fact, they are to jointly preempt resources. When one thread is used up, the next one is used immediately, which reduces the time gap. Roughly the same as process preemption time slice. But still a lot of efficiency has been improved.

Example: When downloading a file, you can divide the file into multiple parts, and then use multiple threads to download at the same time, thereby speeding up the download speed.

3. Comparison of process threads:

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325299308&siteId=291194637