Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How PID (Process Indentifier) is generated in kernel-mode under Windows?

Tags:

kernel

pid

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?

like image 272
J. Rattz Avatar asked Jan 04 '11 12:01

J. Rattz


People also ask

What is the process ID for kernel process?

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.

How do I find the process ID of a Linux kernel?

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).

How are PIDs assigned?

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.


2 Answers

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.

like image 114
vcsjones Avatar answered Sep 17 '22 15:09

vcsjones


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.

like image 41
villintehaspam Avatar answered Sep 18 '22 15:09

villintehaspam