线程与进程的一般情况

发布于 2024-11-07 06:15:20 字数 59 浏览 2 评论 0原文

1)为什么线程创建比进程创建便宜?

2)线程和子进程有什么区别?这与上述问题有何关系?

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 question?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

活泼老夫 2024-11-14 06:15:20

当一个进程被创建时,它被分配堆和栈内存。另一方面,线程只获得一个堆栈并与父进程共享该堆。这意味着即使您只考虑内存分配,创建进程也比创建线程更“昂贵”。

子流程只是由另一个流程创建的流程。它们在其他方面是独立的并拥有自己的存储空间。这是一篇文章,其中介绍了更多细节

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.

っ〆星空下的拥抱 2024-11-14 06:15:20

这个问题的答案可能非常依赖于操作系统,但有一个一般规则:

  1. 进程的线程与其父进程位于同一虚拟内存空间中。因此,创建线程比创建进程更便宜,因为底层操作系统不需要创建完整的虚拟内存空间。

  2. 子进程只是父进程生成的另一个进程。

The answer to this question is probably very OS dependent but a general rule :

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

  2. A subprocess is just another process spawned by a parent.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文