Package com. ffshi. util;
Import java. Io. ioexception;
Import java. util. collections;
Public class javawindowscommandutil {
/**
* @ Param ARGs
*/
Public static void main (string [] ARGs ){
// Todo auto-generated method stub
// Starttask ("E: // fetion // fetion.exe ");
Killtask ("javaw ");
}
/**
* Killing a process
*
* @ Param task
*/
Public static void killtask (string task ){
Try {
Process = runtime.getruntime(cmd.exe C ("tasklist ");
Processing in = New Processing (process. getinputstream ());
Int COUNT = 0;
While (in. hasnextline ()){
Count ++;
String temp = in. nextline ();
If (temp. Contains (task )){
String [] T = temp. Split ("");
// Determine whether the memory occupied by the process is greater than 20 mb
If (integer. parseint (T [T. Length-2]. Replace (",", "")> 20000 ){
Temp = temp. replaceall ("","");
// Obtain the PID
String pid = temp. substring (9, temp. indexof ("console "));
Runtime.getruntime(cmd.exe C ("tskill" + PID );
// Open the CMD window ntsd-C q-p pid in DOS
// Runtime.getruntime(cmd.exe C ("ntsd-C q-P 1528 ");
}
}
// System. Out. println (count + ":" + temp );
}
} Catch (exception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
}
/**
* Display all processes of the Current Machine
*/
Public static void showtasklist (){
Try {
Process = runtime.getruntime(cmd.exe C ("tasklist ");
Processing in = New Processing (process. getinputstream ());
Int COUNT = 0;
While (in. hasnextline ()){
Count ++;
System. Out. println (count + ":" + in. nextline ());
}
} Catch (exception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
}
/**
* Start a process
*
* @ Param task
*/
Public static void starttask (string task ){
Try {
Runtime.getruntime(cmd.exe C (task );
} Catch (ioexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
}
}