Is there a command line utility that kills all processes with a specific command line?
E.g. kill all processes named «java.exe» with a command line that contains «-jar selenium-server.jar». This is possible through process explorer.
asked Oct 7, 2009 at 10:16
ripper234ripper234
11.1k37 gold badges87 silver badges112 bronze badges
6
In Windows XP you can do this easily using WMIC, the WMI Console. From a command prompt, type the following:
wmic Path win32_process Where "CommandLine Like '%-jar selenium-server.jar%'" Call Terminate
Edit:
I replaced the alias ‘process‘ by it full path (‘path win32_process‘) as is Aviator’s port. Note: This alias may not be declared on every OS.
answered Oct 7, 2009 at 12:45
BenoitBenoit
6404 silver badges7 bronze badges
3
If you are using a Windows version which has WMIC command in it. You can try this
wmic path win32_process Where "Caption Like '%java.exe%' AND CommandLine Like '%selenium.jar%'" get ProcessId|more +1
The more +1
removes first line containing the header and prints the PID alone. If there are more than one java process containing selenium.jar then this will return one PID per line.
answered Oct 7, 2009 at 12:44
vpram86vpram86
2,5582 gold badges19 silver badges17 bronze badges
Simple one-liner in powershell:
(Get-WmiObject win32_process -filter "Name='java.exe' AND CommandLine LIKE '%-jar selenium-server.jar%'").Terminate()
answered Jan 14, 2017 at 0:36
wisbuckywisbucky
2,67829 silver badges27 bronze badges
1
I believe you could do this with PowerShell using Get-Process and the StartInfo.Arguments on the process you want.
$procs = Get-Process java
foreach($proc in $procs)
{
if($proc.StartInfo.Arguments -contains "-jar selenium-server.jar")
{
kill $proc
}
}
(I haven’t tested that completely, but you should be able to tweak it to make it work)
answered Oct 7, 2009 at 12:19
brienbrien
2061 silver badge4 bronze badges
1
Powershell:-
$oProcs = get-process explorer;foreach ($oProc in $oProcs){if ($oProc.Path.Contains('C:Windows')) {Stop-Process $oProc.Id}}
suspectus
4,63514 gold badges24 silver badges33 bronze badges
answered Jun 25, 2015 at 20:16
I use a variation of Brien’s PowerShell script.
This outputs command line and other info as well.
$processes = Get-WmiObject Win32_Process -Filter "name = 'java.exe'"
foreach($proc in $processes)
{
if($proc.CommandLine.Contains("selenium-server.jar"))
{
Write-Host "stopping proccess $($proc.ProcessId) with $($proc.ThreadCount) threads; $($proc.CommandLine.Substring(0, 50))..."
Stop-Process -F $proc.ProcessId
} else
{
Write-Host "skipping proccess $($proc.ProcessId) with $($proc.ThreadCount) threads; $($proc.CommandLine.Substring(0, 50))..."
}
}
briantist
1,0238 silver badges10 bronze badges
answered Sep 29, 2015 at 11:40
Jan HJan H
2013 silver badges8 bronze badges
Another powershell variation. It’s basically the same, perhaps easier to type and remember. -match can actually take a regular expression.
get-wmiobject win32_process | where commandline -match selenium-server.jar
| remove-wmiobject
answered Jan 31, 2019 at 17:24
js2010js2010
5475 silver badges6 bronze badges
3
Use the free PsKill:
pskill java.exe
1
Sometimes when an application in Windows hangs, freezes and stops responding the only way to terminate it is to kill from the command-line.
The taskkill
command in Windows serves for terminating tasks by name or by process id (PID).
In this note i am showing how to find and kill a process by its name or by PID and how to identify a process by the listening port.
I am also showing how to troubleshoot “The process could not be terminated” and “Access denied” errors.
Cool Tip: Get the return code from the last command or application! Read more →
List all Windows processes and find the full name of a process to kill (case insensitive):
C:> tasklist | findstr /I process_name
Kill the process by name:
C:> taskkill /IM process_name.exe
Kill Process by PID
List all Windows processes and find the PID of a process to kill (case insensitive):
C:> tasklist | findstr /I process_name
Kill the process by PID:
C:> taskkill /PID process_id
Kill Process by Port
List all Windows processes listening on TCP and UDP ports and find the PID of a process running on a specific port:
C:> netstat -ano | findstr :port
Find the name of a process by its PID:
C:> tasklist /FI "pid eq process_id"
Kill the process by name or by PID:
C:> taskkill /IM process_name.exe - or - C:> taskkill /PID process_id
Cool Tip: Windows grep
command equivalent in CMD and PowerShell! Read more →
Troubleshooting
Kill the process forcefully in case of the following error:
ERROR: The process with PID XXX could not be terminated.
Reason: This process can only be terminated forcefully (with /F option).
C:> taskkill /F /IM process_name.exe - or - C:> taskkill /F /PID process_id
If you get an “Access is denied” error, you should open the command prompt as an administrator:
ERROR: The process with PID XXX could not be terminated.
Reason: Access is denied
To run the CMD as an administrator, press ⊞ Win keybutton to open the start menu, type in cmd
to search for the command prompt and press Ctrl + Shift + Enter to launch it as administrator.
When you start an app, the operating system creates a process for an executable file of the app. It contains the program code and its current activity. Windows assigns a special number known as Process Identifier (PID) which is unique for every process. There are a number of reasons you might want to kill a process, and different methods you can use to terminate it. Here is how it can be done.
If an app stops responding, consumes a lot of system resources or behaves unexpectedly and doesn’t allow you to quit it, you might want to kill its process to forcefully close the app. Traditionally, Windows allowed using Task Manager and the command prompt for these tasks. In addition to these methods, you can use PowerShell. Here is how.
To kill a process in Windows 10, do the following.
- Open Task Manager.
- Click on «More details» in the bottom right corner to enter Full view mode.
- Select the desired app in the app list.
- Click on the End task button or hit the Del key on the keyboard.
You are done.
This is Task Manager’s most well known method.
Note: The same can be done from the Details tab. It is a special tab which lists process names instead of app names. There you can select a process in the list and either click on the End process button or hit the Del key.
Using the End Task button means Windows first tries to see for a certain timeout if the process has really stopped responding, and attempts to collect a crash or memory dump of the process. It then terminates the app.
Tip: We highly recommend you read the article How to end a process quickly with Task Manager in Windows 10 to learn all Task Manager tricks. Also, you can get the classic Task Manager app in Windows 10 to end processes or tasks.
Another classic method to close a process is the console tool taskill. It comes bundled with modern versions of Windows.
Kill a process using Taskkill
Note: Some processes are running as Administrator (elevated). In order to kill them, you need to open an elevated command prompt instance.
- Open the command prompt as the current user or as Administrator.
- Type tasklist to see the list of running processes and their PIDs. Since the list might be very long, you can use a pipe character with the more command.
tasklist | more
- To kill a process by its PID, type the command:
taskkill /F /PID pid_number
- To kill a process by its name, type the command
taskkill /IM "process name" /F
For example, to kill a process by its PID:
taskkill /F /PID 1242
To kill a process by its name:
taskkill /IM "notepad.exe" /F
Taskkill supports many useful options which you can use to terminate apps. You can learn them by running it as follows: taskkill /?
. Using taskkill, you can close all not responding tasks at once in Windows 10.
Kill a process using PowerShell
Note: To kill a process which runs elevated, you need to open PowerShell as Administrator.
- Open PowerShell. If required, run it as Administrator.
- Type the command
Get-Process
to see the list of running processes. - To kill a process by its name, execute the following cmdlet:
Stop-Process -Name "ProcessName" -Force
- To kill a process by its PID, run the command:
Stop-Process -ID PID -Force
Examples:
This command will close the notepad.exe process.
Stop-Process -Name "Notepad" -Force
The next command will close a process with PID 2137.
Stop-Process -ID 2137 -Force
If you need to kill a Store app, see the following article:
How to Terminate Store Apps in Windows 10
That’s it.
Support us
Winaero greatly relies on your support. You can help the site keep bringing you interesting and useful content and software by using these options:
If you like this article, please share it using the buttons below. It won’t take a lot from you, but it will help us grow. Thanks for your support!
Windows — Kill a process using the command-line
Windows — Kill a process using the command-line
Would you like to learn how to kill a process using the command-line on a computer running Windows? In this tutorial, we are going to show you how to kill a task using the command-line on a computer running Windows.
• Windows 2012 R2
• Windows 2016
• Windows 2019
• Windows 10
Windows Playlist:
On this page, we offer quick access to a list of videos related to Windows installation.
Don’t forget to subscribe to our youtube channel named FKIT.
Windows Related Tutorial:
On this page, we offer quick access to a list of tutorials related to Windows.
Tutorial Windows — Kill a process using the command-line
Start a new command-line prompt.
List the processes running on the computer.
Here is the command output.
Kill a process using the process ID.
In our example, we killed the process named MSPAINT, which had the process ID 3724.
Change the process ID number to the process that you want to kill.
Kill a process using the process name.
In our example, we killed all processes named MSPAINT.EXE.
Change the process name to the process that you want to kill.
You may also use wildcards on the process name.
In our example, we killed all processes in which the name started with MSPAIN.
Congratulations! You are able to terminate processes using the command-line.
VirtualCoin CISSP, PMP, CCNP, MCSE, LPIC22021-01-01T02:43:25-03:00
Related Posts
Page load link
Join Our Newsletter
Ok