Windows PIDs: An Absolute Beauty

Photo by Tadas Sar on Unsplash

Windows PIDs: An Absolute Beauty

In this article, you'll learn an interesting fact about the Windows operating system.

We all have come across the famous application called Task Manager. But have you looked at the details tab, which shows PID or the Process ID for each Process running in the system?

How to Find Process ID of Process using a Port in Windows

I just realized that all the Process IDs are in even numbers and divisible by four. This got me curious, why would every PID have to be an even number ??

Code Reuse

The Answer for this comes from a code that Windows have reused for the Process, which comes from the header called ntdef.h which you can see here from a GitHub repository for the Windows SDK.

In short, they have ignored the lower-order two bits in the hex representation, leaving us with numbers that will always be divisible by four.

0x10 == 16

To understand this in detail, we have to learn the basics of hexadecimal to decimal conversion. Which is as much scary as it sounds, NOOO it is not!

Now if you have eliminated the last bit in the table of hexadecimal, we will never get an odd number since the rest of the values in the table will only yield even numbers. And they taught us in our schools that even numbers are divisible by four.


Here are some examples of the hexadecimal to decimal conversion that will only yield even numbers as a result.

Did you find this article valuable?

Support Mohanraj R by becoming a sponsor. Any amount is appreciated!