I would like to know how Process Identifier(s) (aka PID)s are generated under Windows. Is it unique across different machines? e.g., consider the 5856 id that's currently assigned to my Firefox program. Is it same for the same executable image under another machine?
Every process has a unique identifier which it is represented by, called as the process ID(pid). The first process that the kernel runs is called the idle process and has the pid 0. The first process that runs after booting is called the init process and has the pid 1.
In the GNU C Library implementation running on Linux, the process ID is the thread group ID of all threads in the process. You can get the process ID of a process by calling getpid . The function getppid returns the process ID of the parent of the current process (this is also known as the parent process ID).
A PID (i.e., process identification number) is an identification number that is automatically assigned to each process when it is created on a Unix-like operating system. A process is an executing (i.e., running) instance of a program. Each process is guaranteed a unique PID, which is always a non-negative integer.
A PIDs generation is mostly a secret that Microsoft won't officially document - because they would have to stick to that implementation once they've documented it. However, it is always a multiple of 4 - but this isn't a behavior you should rely on. They aren't unique, and they can be re-used.
Raymond Chen mentions this in his blog.
Process identifiers are not unique across different machines. They can be reused on the same machine for later processes and will typically not be the same between two invocations of the same executable.
You are not supposed to care about how it is being generated - the only thing that you can be sure of is that the process identifier uniquely identifies a single running process, i.e. there will only be one process having that identifier at any one time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With