零线程进程?
一个进程中是否必须至少有一个线程?进程是否可能没有任何线程,或者这没有意义?
Does a process have to have at least one thread in it? Is it possible for a process to be void of any threads, or does this not make sense?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
一个进程通常至少有一个线程。 维基百科有这样的定义:
MSDN 支持这一点:
尽管它接着说:
这意味着如果单线程单元和多线程单元的数量都可以为零。然而,这个过程不会做太多:)
A process usually has at least one thread. Wikipedia has the definition:
The MSDN backs this up:
Though it does go on to say:
Which implies that if both the number of single-threaded apartments and multithreaded apartments could be zero. However, the process wouldn't do much :)
在类 Unix 操作系统中,可能存在 僵尸进程,其中的条目仍然存在于进程表,即使没有(不再)任何线程。
In Unix-like operating systems, it's possible to have a zombie process, where an entry still exists in the process table even though there are no (longer) any threads.
您可以选择不使用显式线程库,或者没有线程概念的操作系统(因此不称其为线程),但对于大多数现代编程来说,所有程序都至少有一个执行线程(通常称为作为主线程或 UI 线程或类似)。如果存在,则该过程也存在。
思想实验:零执行线程的进程会做什么?
You can choose not to use an explicit threading library, or an operating system that has no concept of threads (and so doesn't call it a thread), but for most modern programming all programs have at least one thread of execution (generally referred to as a main thread or UI thread or similar). If that exits, so does the process.
Thought experiment: what would a process with zero threads of execution do?
从理论上讲,我不明白为什么不。但这对于流行的操作系统来说是不可能的。
进程通常由几个不同的部分组成:
理论上,进程可以在没有线程的情况下作为 RPC 服务器存在。其他进程会进行 RPC 调用,从而在服务器进程中生成线程,然后当函数返回时这些线程就会消失。我不知道有任何操作系统可以这样工作。
在大多数操作系统上,进程会在最后一个线程退出时或主线程退出时退出。
In theory, I don't see why not. But it would be impossible with the popular operating systems.
A process typically consists of a few different parts:
In theory, a process could exist with no threads as an RPC server. Other processes would make RPC calls which spawn threads in the server process, and then the threads disappear when the function returns. I don't know of any operating systems that work this way.
On most OSs, the process exits either when the last thread exits, or when the main thread exits.
“main”本身就是线程。它是一个被执行的线程。因此,每个进程至少在一个线程上运行。
"main" itself is thread. Its a thread that gets executed. So, every process runs on at least one thread.