(Feel free to edit the title if you can think of something better)

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.

link|improve this question

64% accept rate
3  
I believe both the answers below are wrong, as you arent just asking how to kill a .exe process, you are asking how to kill a .exe process which contains a specific command line – admintech Oct 7 '09 at 10:45
2  
Are you only talking about Windows? Your examples and the supplied answers make it seem like you are, but you didn't specify this. – Nathan Fellman Oct 7 '09 at 10:45
Can you explain "how this is possible through Process Explorer?" I just launched a java - jar<app-name> and it shows only java.exe – Sathya Oct 7 '09 at 12:00
i bet he/she meant "sysinternals process explorer" – akira Oct 7 '09 at 12:35
Sysinternals Process Explorer, of course. You can view much information about running processes from it, including their command line. – ripper234 Oct 7 '09 at 14:22
show 1 more comment
feedback

5 Answers

up vote 7 down vote accepted

In Windows XP, you can do this easyly uing WMIC, the WMI Console. From a command propt, 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. This alias may not be declared on every OS.

link|improve this answer
1  
+20 That's it! Dammit :) I too was following the WMIC. But I was doing it from within the WMIC console and wasn't being able to apply LIKE. Was getting syntax errors, which were forcing me to use '=', which in turn forced me to input the whole CommandLine field. Glad to know LIKE works outside the WMIC console. Should have thought of that. Kudos to you – A Dwarf Oct 7 '09 at 13:04
feedback

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.

link|improve this answer
feedback

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)

link|improve this answer
feedback

PsKill:

pskill java.exe

link|improve this answer
you missed the 2nd part of the question: "specific commandline"... not the first java.exe, that comes along .. neither all java.exe processes – akira Oct 7 '09 at 11:33
feedback

for windows XP at least:

taskkill /f /im java.exe

link|improve this answer
you missed the 2nd part of the question: "specific commandline"... not the first java.exe, that comes along .. neither all java.exe processes – akira Oct 7 '09 at 11:35
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.