Find process running windows

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.

C++, How to determine if a Windows Process is running?

This is concerning Windows XP processes.

I have a process running, let’s call it Process1. Process1 creates a new process, Process2, and saves its id.

Now, at some point Process1 wants Process2 to do something, so it first needs to make sure that Process2 is still alive and that the user has not not killed it.

How can I check that this process is still running? Since I created it, I have the Process ID, I would think there is some library function along the lines of IsProcessIDValid( id ) but I can’t find it on MSDN

12 Answers 12

You can use GetExitCodeProcess . It will return STILL_ACTIVE (259) if the process is still running (or if it happened to exit with that exit code 🙁 ).

Читайте также:  Radeon 6790 windows 10

The process handle will be signaled if it exits.

So the following will work (error handling removed for brevity):

Note that process ID’s can be recycled — it’s better to cache the handle that is returned from the CreateProcess call.

You can also use the threadpool API’s (SetThreadpoolWait on Vista+, RegisterWaitForSingleObject on older platforms) to receive a callback when the process exits.

EDIT: I missed the «want to do something to the process» part of the original question. You can use this technique if it is ok to have potentially stale data for some small window or if you want to fail an operation without even attempting it. You will still have to handle the case where the action fails because the process has exited.

The solution provided by @user152949, as it was noted in commentaries, skips the first process and doesn’t break when «exists» is set to true. Let me provide a fixed version:

Another way of monitoring a child-process is to create a worker thread that will :

  1. call CreateProcess()
  2. call WaitForSingleObject() // the worker thread will now wait till the child-process finishes execution. it’s possible to grab the return code (from the main() function) too.

I found this today, it is from 2003. It finds a process by name, you don’t even need the pid.

You can never check and see if a process is running, you can only check to see if a process was running at some point in the recent past. A process is an entity that is not controlled by your application and can exit at any moment in time. There is no way to guaranteed that a process will not exit in between the check to see if it’s running and the corresponding action.

The best approach is to just do the action required and catch the exception that would be thrown if the process was not running.

call EnumProcesses() and check if the PID is in the list.

JaredPar is right in that you can’t know if the process is running. You can only know if the process was running at the moment you checked. It might have died in the mean time.

You also have to be aware the PIDs can be recycled pretty quickly. So just because there’s a process out there with your PID, it doesn’t mean that it’s your process.

Have the processes share a GUID. (Process 1 could generate the GUID and pass it to Process 2 on the command line.) Process 2 should create a named mutex with that GUID. When Process 1 wants to check, it can do a WaitForSingleObject on the mutex with a 0 timeout. If Process 2 is gone, the return code will tell you that the mutex was abandoned, otherwise you’ll get a timeout.

You may find if a process (given its name or PID) is running or not by iterating over the running processes simply by taking a snapshot of running processes via CreateToolhelp32Snapshot, and by using Process32First and Process32Next calls on that snapshot.

Then you may use th32ProcessID field or szExeFile field of the resulting PROCESSENTRY32 struct depending on whether you want to search by PID or executable name. A simple implementation can be found here.

While writing a monitoring tool, i took a slightly different approach.

It felt a bit wasteful to spin up an extra thread just to use WaitForSingleObject or even the RegisterWaitForSingleObject (which does that for you). Since in my case i don’t need to know the exact instant a process has closed, just that it indeed HAS closed.

I’m using the GetProcessTimes() instead:

GetProcessTimes() will return a FILETIME struct for the process’s ExitTime only if the process has actually exited. So is just a matter of checking if the ExitTime struct is populated and if the time isn’t 0;

Читайте также:  Windows 10 установка репаков

This solution SHOULD account the case where a process has been killed but it’s PID was reused by another process. GetProcessTimes needs a handle to the process, not the PID. So the OS should know that the handle is to a process that was running at some point, but not any more, and give you the exit time.

How to find the process id of a running Java process on Windows? And how to kill the process alone?

I want to kill the particular Java process in Windows, like in Linux ( ps -aux to get processid and then kill processid to kill the process).

8 Answers 8

You can use the jps utility that is included in the JDK to find the process id of a Java process. The output will show you the name of the executable JAR file or the name of the main class.

Then use the Windows task manager to terminate the process. If you want to do it on the command line, use

You can also find the PID of a java program with the task manager. You enable the PID and Command Line columns View -> Select Columns and are then able to find the right process.

Your result will be something like this :

After setting the path of your jdk use JPS .Then You can eaisly kill it by Task Manager
JPS will give you all java processes

This will work even when there are multiple instance of jar is running

The solution I found is very simple. Use Window’s WMIC & Java’s Runtime to locate & kill the process.

Part 1: You need to put some sort of identifier into your app’s startup command line. E.g. something like:

Part 2: When you run your app, make sure to include the string. Let’s say you start it from within Java, do the following:

Part 3: To kill the process, use Window’s WMIC. Just make sure you app was started containing your id from above:

In windows XP and later, there’s a command: tasklist that lists all process id’s.

For killing a process in Windows, see:

You can execute OS-commands in Java by:

If you need to handle the output of a command, see example: using Runtime.exec() in Java

This is specific to Windows. I was facing the same issue where I have to kill one specific java program using taskkill. When I run the java program, tasklist was showing the same program with Image name set as java.exe. But killing it using taskkill /F java.exe will stop all other java applications other than intended one which is not required.

So I run the same java program using:

Here start command will open a new window and run the java program with window’s title set to MyProgramName.

Now to kill this java-program use the following taskkill command:

Your Java program will be killed only. Rest will be unaffected.

How to check if a process is running via a batch script

How can I check if an application is running from a batch (well cmd) file?

I need to not launch another instance if a program is already running. (I can’t change the app to make it single instance only.)

Also the application could be running as any user.

18 Answers 18

Another possibility I came up with, inspired by using grep, is:

It doesn’t need to save an extra file, so I prefer this method.

Here’s how I’ve worked it out:

The above will open Notepad if it is not already running.

Edit: Note that this won’t find applications hidden from the tasklist. This will include any scheduled tasks running as a different user, as these are automatically hidden.

Читайте также:  How to install njrat on kali linux

I like Chaosmaster’s solution! But I looked for a solution which does not start another external program (like find.exe or findstr.exe). So I added the idea from Matt Lacey’s solution, which creates an also avoidable temp file. At the end I could find a fairly simple solution, so I share it.

This is working for me nicely.

The suggestion of npocmaka to use QPROCESS instead of TASKLIST is great but, its answer is so big and complex that I feel obligated to post a quite simplified version of it which, I guess, will solve the problem of most non-advanced users:

The code above was tested in Windows 7, with a user with administrator rigths.

Under Windows you can use Windows Management Instrumentation (WMI) to ensure that no apps with the specified command line is launched, for example:

wmic process where (name=»nmake.exe») get commandline | findstr /i /c:»/f load.mak» /c:»/f build.mak» > NUL && (echo THE BUILD HAS BEEN STARTED ALREADY! > %ALREADY_STARTED% & exit /b 1)

I use PV.exe from http://www.teamcti.com/pview/prcview.htm installed in Program Files\PV with a batch file like this:

TrueY’s answer seemed the most elegant solution, however, I had to do some messing around because I didn’t understand what exactly was going on. Let me clear things up to hopefully save some time for the next person.

TrueY’s modified Answer:

Anyway, I hope that helps. I know sometimes reading batch/command-line can be kind of confusing sometimes if you’re kind of a newbie, like me.

The answer provided by Matt Lacey works for Windows XP. However, in Windows Server 2003 the line

INFO: No tasks are running which match the specified criteria.

which is then read as the process is running.

I don’t have a heap of batch scripting experience, so my soulution is to then search for the process name in the search.log file and pump the results into another file and search that for any output.

I hope this helps someone else.

I like the WMIC and TASKLIST tools but they are not available in home/basic editions of windows.Another way is to use QPROCESS command available on almost every windows machine (for the ones that have terminal services — I think only win XP without SP2 , so practialy every windows machine):

QPROCESS command is not so powerful as TASKLIST and is limited in showing only 12 symbols of process name but should be taken into consideration if TASKLIST is not available.

More simple usage where it uses the name if the process as an argument (the .exe suffix is mandatory in this case where you pass the executable name):

The difference between two ways of QPROCESS usage is that the QPROCESS * will list all processes while QPROCESS some.exe will filter only the processes for the current user.

Using WMI objects through windows script host exe instead of WMIC is also an option.It should on run also on every windows machine (excluding the ones where the WSH is turned off but this is a rare case).Here bat file that lists all processes through WMI classes and can be used instead of QPROCESS in the script above (it is a jscript/bat hybrid and should be saved as .bat ):

And a modification that will check if a process is running:

The two options could be used on machines that have no TASKLIST .

The ultimate technique is using MSHTA . This will run on every windows machine from XP and above and does not depend on windows script host settings. the call of MSHTA could reduce a little bit the performance though (again should be saved as bat):

Оцените статью