PowerShell 中的进程与实例与运行空间

Process vs Instance vs Runspace in PowerShell

[Powershell]::create() - 方法在 "current or a new runspace" 中创建一个新的 PowerShell-"Instance"。

有人可以解释术语 processinstancerunspace 和(也许 thread) 在这方面相互关联。 如果可能,通俗地说?

您拥有的术语不可互换,并且不会做同样的事情。

进程是运行指令集的程序。

线程是程序中的单个 运行 指令。

多线程是多条指令同时运行。每个都需要一个单独的线程。

Runspace 在同一个 powershell 进程中,但调用一个新的 powershell 引擎以便 运行 它的代码不干扰当前的 powershell 脚本线程。

实例是一个包含的 运行 代码。它是一个描述符。

下面是一些例子

我可以有一个流程实例。 我可以有一个线程实例。 我可以有一个 Runspance 的实例。

根据评论编辑以扩展答案

"So in the example ive posted above ([Powershell]::create()), is that an instance of a thread, process or runspace?"

所以我们有一个 Powershell 应用程序。发生的事情是此应用程序启动一个运行空间,您的命令将在其中执行,并设置一个位置来创建 Powershell 对象。每次打开 powershell 控制台时,都会启动另一个 运行space。

[Powershell]::create() 它会创建一个对象,您可以在其中确定 运行 以及 运行 所在的 运行 空间。如果您不选择 运行 空间,那么它会为您创建一个空间。

所以 [Powershell] 是 运行?(脚本)和 运行(一个运行空间)

Runspace 是如何运行?(在 powershell 引擎上)

您可以将 [Powershell]::Create() 视为单独线程上的新 powershell 会话。此会话将创建一些默认值 运行space,但您可以将其更改为另一个。与 Start-Process(独立进程)和 Start-Job(子进程)不同,[Powershell]::Create() 运行与您的主脚本在同一进程上并与其共享内存 space .这意味着您可以在主会话和子会话之间交换实际的 .net 对象。如果会话 运行 在单独的进程上,它们只能与 textual/serialized 数据交换。