Threads Vs Processes Generally
1) Why is thread creation less expensive than process creation?
2) What is the difference between a thread and a subprocess? How would this relate to the above quest开发者_开发问答ion?
When a process is created it is allocated heap and stack memory. Threads on the other hand only get a stack and share the heap with the parent process. This means that even if you just consider memory allocation it is more "expensive" to create a process than a thread.
Subprocesses are simply processes that were created by another process. They are otherwise independent and get their own memory space. Here's an article that goes into some more detail.
The answer to this question is probably very OS dependent but a general rule :
Threads of a process live in the same virtual memory space as their parent. So a thread creation is less expensive than a process creation because the underlying operating system doesn't need to create a full virtual memory space.
A subprocess is just another process spawned by a parent.
精彩评论