Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the differences between a Process ID and a Process handle

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.

like image 422
smwikipedia Avatar asked Nov 08 '10 02:11

smwikipedia


People also ask

What is a process handle?

ProcessHandle identifies and provides control of native processes. Each individual process can be monitored for liveness, list its children, get information about the process or destroy it.

What is meant by process ID?

A process ID is a unique, positive number that represents a process. Because the process ID is a unique identifier, it can be used to direct signals between processes. See Signals for more information about signals.

What can you do with a process ID?

The Process ID (or PID) is mostly used to identify each running or suspended process within a system. Knowing an app's PID helps you identify programs running multiple instances, such as when editing two different files using the same app.

Is process ID same as thread ID?

The thread ID of the initial (main) thread is the same as the process ID of the entire process. Thread IDs for subsequently created threads are distinct. They are allocated from the same numbering space as process IDs. Process IDs and thread IDs are sometimes also referred to collectively as task IDs.

How do I find the process ID of a service?

How to get PID using Task Manager. Press Ctrl+Shift+Esc on the keyboard. Go to the Processes tab. Right-click the header of the table and select PID in the context menu.

Is process ID unique?

Process identifiers can be reused by the system. The Id property value is unique only while the associated process is running. After the process has terminated, the system can reuse the Id property value for an unrelated process.


2 Answers

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
like image 175
Faheem Avatar answered Nov 06 '22 09:11

Faheem


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.

like image 43
DennyRolling Avatar answered Nov 06 '22 08:11

DennyRolling