- Finding the process ID
- Task Manager
- The tasklist command
- TList utility
- The .tlist debugger command
- PowerShell Get-Process command
- CSRSS and user-mode drivers
- Solved — How to Find Out the PID (Process ID) in Windows
- Get PID by Task Manager
- Get PID by Command Line
- PowerShell
- Get the PID of a Windows service
- 3 Answers 3
- Find the PID of a process that uses a port on Windows
- 7 Answers 7
- How to get own process pid from the command prompt in Windows
- 13 Answers 13
Finding the process ID
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.
This topic describes how you can determine the PID for a given app using Task Manager, the tasklist Windows command, the TList utility, or the debugger.
Task Manager
Task Manager can be opened in a number of ways, but the simplest is to select Ctrl+Alt+Delete, and then select Task Manager.
In Windows 10, first click More details to expand the information displayed. From the Processes tab, select the Details tab to see the process ID listed in the PID column.
Click on any column name to sort. You can right click a process name to see more options for a process.
Some kernel errors may cause delays in Task Manager’s graphical interface.
The tasklist command
Use the built in Windows tasklist command from a command prompt to display all processes, their PIDs, and a variety of other details.
Use tasklist /? to display command line help.
TList utility
Task List Viewer (TList), or tlist.exe, is a command-line utility that displays the list of tasks, or user-mode processes, currently running on the local computer. TList is included in the Debugging Tools for Windows. For information on how to download and install the debugging tools, see Download Debugging Tools for Windows.
If you installed the Windows Driver Kit in the default directory on a 64 bit PC, the debugging tools are located here:
C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\
When you run TList from the command prompt, it will display a list of all the user-mode processes in memory with a unique PID number. For each process, it shows the PID, process name, and, if the process has a window, the title of that window.
For more information, see TList.
The .tlist debugger command
If there’s already a user-mode debugger running on the system in question, the .tlist (List Process IDs) command will display a list of all PIDs on that system.
PowerShell Get-Process command
To work with automation scripts, use the Get-Process PowerShell command. Specify a specific process name, to see the process ID for that process.
For more information, see Get-Process.
CSRSS and user-mode drivers
To debug a user-mode driver running on another computer, debug the Client Server Run-Time Subsystem (CSRSS) process. For more information, see Debugging CSRSS.
Solved — How to Find Out the PID (Process ID) in Windows
PID, the abbreviation of Process Identifier, is a unique number used to identify every running process or service in operating system like Windows, MacOS, and Linux. In this post, we will walk you through three methods of how to find out the PID (Process ID) in Windows.
Get PID by Task Manager
Whether in Windows 7 or Windows 10, you can both get the PID (Process ID) by Task Manager. Here are the detailed steps.
Step 1: Press Ctrl + Shift + Esc simultaneously to open Task Manager window.
Step 2: If the window shows in a simplified summary mode, click More details in the bottom left corner.
Step 3: On Task Manager window, click Details tab. Then the PID is shown on the screen. Finally, you can check the process id of every running process and deal with it as you want.
TIPS: If PID can’t be found on Task Manager in Windows, you can refer to the following steps to show PID on Task Manager. Firstly, on the Details tab, right-click the header of any column (like Name, Status) and then click Select columns. Then on the popup window, check the checkbox of PID and click OK to save the change. Finally, the PID will be shown on Task Manager.
Get PID by Command Line
It is also so convenient that you can check PID (Process ID) by command line within just two steps. Here is the guide.
Step 1: Press Windows Key + R to open a run window. Then type cmd and press Enter to open Command Prompt window.
Step 2: In Command Prompt window, type tasklist and press Enter. Then, the details of running processes or services including the PID are listed on the screen.
PowerShell
In the matter of getting process id, PowerShell offers the same feature as Command Prompt does and even the command line is the same. You just need to type PowerShell in Windows search box and press Enter to open PowerShell window. Then you can type tasklist and press Enter. Finally, the details of running processes including PID are listed as follows.
Get the PID of a Windows service
Could anyone help me to know how to get the PID of a Windows service?
I need to get the PID in order to run the following command:
3 Answers 3
Assuming you know the name of the EXE the service uses and there is exactly one of them:
The method Process.GetProcessesByName(«yourservice») returns an Array of Processes with your specified name, so in case you don’t know how much of «yourservice.exe» runs simultaneously you might need a foreach loop.
What the other answers neglect is the fact that a single process can also host multiple, autonomous services. The multiple instances of the svchost.exe process, each hosting a couple of services, is the best example.
So in general, it is absolutely unsafe to try to kill an arbitrary service by killing it’s hosting process (I assume that is what you attempt to do, since you refer to taskkill.exe ). You might take down several unrelated services in the process.
If you do know that the service’s process only hosts the service you care about, than you can choose the strategy as suggested by @M C in his/her answer.
Alternatively, you can also use the ServiceController class to open a handle to your service and then use it (via the ServiceHandle property) to P/Invoke the QueryServiceStatusEx function to find out the Process ID you want to know.
If you need more details, you should clarify what it is that you’re actually trying to achieve. It is not clear from your question.
Update Here is some code I ripped out of an existing project that should do what you want, given you have a ServiceController instance. _As said above, use with care!__
Find the PID of a process that uses a port on Windows
My service crash on startup with the classic:
How can I find the process for killing it?
7 Answers 7
Just open a command shell and type (saying your port is 123456):
You will see everything you need.
The headers are:
Find the PID of a process that uses a port on Windows (e.g. port: «9999»)
-a Displays all connections and listening ports.
-o Displays the owning process ID associated with each connection.
-n Displays addresses and port numbers in numerical form.
Then kill the process by PID
/F — Specifies to forcefully terminate the process(es).
Note: You may need an extra permission (run from administrator) to kill some certain processes
Command:
Output:
Now cut the process ID, «10396», using the for command in Windows.
Command:
Output:
If you want to cut the 4th number of the value means «LISTENING» then command in Windows.
Command:
Output:
If you want to do this programmatically you can use some of the options given to you as follows in a PowerShell script:
However; be aware that the more accurate you can be the more precise your PID result will be. If you know which host the port is supposed to be on you can narrow it down a lot. netstat -aon | findstr «0.0.0.0:9999» will only return one application and most llikely the correct one. Only searching on the port number may cause you to return processes that only happens to have 9999 in it, like this:
The most likely candidate usually ends up first, but if the process has ended before you run your script you may end up with PID 12331 instead and killing the wrong process.
How to get own process pid from the command prompt in Windows
I’m trying to find a way to get my own PID from a command prompt (for later use in bat scripts).
So far the only useful way I found was to use getpids.exe from here : http://www.scheibli.com/projects/getpids/index.html, but I’m looking for a command that’s «built in» to Windows.
I’m looking for a «bullet proof» way. No assumptions about my process being the only cmd.exe or anything.
13 Answers 13
Since none of the other solutions are bulletproof and built in, I figured I’d offer the following solution, but note that you’ll need to parse/save the results somehow:
Expanding upon Tony Roth’s answer:
Using the WINDOWTITLE filter avoids the pipe so you can put it in a for loop and assign it to a variable with SET if you like:
Removing the /v makes it quicker, and the /NH gets rid of the header line. You need the wildcard after «uniqueTitle» because the window title actually contains the current command (thus it would go on and on if you tried to match it fully).
Using PowerShell + WMI :
(as always, double the % sign with for in batch files)
I believe the following is bulletproof, provided the user has access to WMIC and TEMP points to a valid path where the user has write privileges. This is the end result of some collaborative work at http://www.dostips.com/forum/viewtopic.php?f=3&t=6133.
The script establishes an exclusive lock on a temporary file that incorporates the current time into the name. There can only be a collision if two like named batch processes attempt to get the PID within the same 0.01 second time interval, in which case only one will succeed.
Any process that fails will repeatedly loop back and try again with a new lock file path until it succeeds.