进程ID和进程句柄有什么区别

发布于 2024-10-01 05:59:07 字数 731 浏览 1 评论 0原文

进程ID是唯一标识进程的数字。进程句柄也是唯一标识进程内核对象的数字。

为什么我们需要它们两者,因为它们中的任何一个都可以识别进程。

我认为答案可能在于进程和进程内核对象之间的映射关系。是否可以将多个进程内核对象映射到单个进程?并且每个进程内核对象都有自己的进程句柄。这样每个进程内核对象都可以代表不同的访问模式或类似的东西。

当我使用 MiniDumpWriteDump() 时,出现了这个问题 函数,其声明如下:

BOOL WINAPI MiniDumpWriteDump(
  __in  HANDLE hProcess,
  __in  DWORD ProcessId,
  __in  HANDLE hFile,
  __in  MINIDUMP_TYPE DumpType,
  __in  PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
  __in  PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
  __in  PMINIDUMP_CALLBACK_INFORMATION CallbackParam
);

所以它的参数包括进程id和进程句柄。我只是不知道为什么有必要同时拥有它们。

非常感谢您的见解。

A process ID is a number that uniquely identifies a process. A process handle is also a number that uniquely identifys a process kernal object.

Why do we need them both since either of them can identify a process.

I think the answer may lie in the mapping relationship betweeen a process and a process kernel object. Is it true that more than one process kernel objects can be mapped to a single process? And each process kernel object has its own process handle. So that each of the process kernel object could represent different access mode or things like that.

This question came to me when I am using the MiniDumpWriteDump() function, which is declared like this:

BOOL WINAPI MiniDumpWriteDump(
  __in  HANDLE hProcess,
  __in  DWORD ProcessId,
  __in  HANDLE hFile,
  __in  MINIDUMP_TYPE DumpType,
  __in  PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
  __in  PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
  __in  PMINIDUMP_CALLBACK_INFORMATION CallbackParam
);

So it's parameters include both process id and process handle. I just don't know why it's necessary to have them both.

Many thanks for your insights.

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

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

发布评论

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

评论(2

黯淡〆 2024-10-08 05:59:07

进程句柄是

  1. 获取它的任意
  2. 内部进程。私有,不能在线程/进程之间共享
  3. 它也具有安全访问权限

而进程ID是

  1. 唯一的通用
  2. 的,公共的,因此可以在线程/进程之间共享

Process Handle is

  1. Arbitrary
  2. Internal to process that acquired it. Private and can't be shared between threads/processes
  3. It carries security access rights too

While Process ID is

  1. Unique
  2. Universal, public, so it can be shared between threads/processes
那支青花 2024-10-08 05:59:07

区别在于“id”是系统范围内的编号,用于唯一标识进程。另一方面,“handle”是一个不透明的值,它将进程和对该进程的访问连接到您的程序。您可能对同一进程有多个不同的句柄。

我不知道为什么 MiniDumpWriteDump 两者都采用。

the difference is that 'id' is system-wide number which uniquely identifies the process. 'handle' on the other hand is an opaque value which connects process and access to that process to your program. you can potentially have multiple different handles to the same process.

I don't know why MiniDumpWriteDump takes both.

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