In Windows, is 0 valid PID for a process or is it reserved by OS? It would be nice if you can provide a link to a doc that says it is reserved or what. Thank!
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.
The if (PID == 0) evaluates the return value. If PID is equal to zero then printf() is executed in the child process, but not in the parent process. The else part of the condition is executed in the parent process and the child process but only the parent process will execute the else part of the condition.
Each process running in Windows is assigned a unique decimal number called the process ID (PID). This number is used in a number of ways, for example to specify the process when attaching a debugger to it.
No error signal would cause any correction. However, zero is not very useful as a PID in a controller, but technically, it's valid. Hence, the PID 0 is often referred to as an idle process.
Open task manager - switch to the processes tab (maybe click "View", "Show columns" and enable the PID column).
PID 0 is the System Idle Process. Since that process isn't really a process and never exits, I suspect that it is always the case.
No documentation available to me, but I'm pretty certain this is always going to be the case.
It's not stated anywhere but it comes down to how the kernel handle table works. This same object is used for both process handles and process/thread IDs. It happens that handle values all start at 0x4, and PsInitialSystemProcess is the first process to be created, so it gets a PID of 4. Idle process isn't actually a process and you can't open it. It probably doesn't have a PID for most intents and purposes but most tools consider it to be 0.
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