Killing system process from javaBy neokrates, written on May 20, 2010 |
java snippet |
- neokrates
- Email: uwarov@yahoo.com
- Website: http://www.thinkplexx.com
- Join date: 05-31-09
- Posts: 20
Rate it
Ad
Poll
Loading ...
Most popular search terms:
Stats
-
Since publication, this page was visited 573 time(s).
This example explained here
import java.io.File; import java.io.IOException; import org.apache.commons.exec.CommandLine; import org.apache.commons.exec.DefaultExecutor; import org.apache.commons.exec.ExecuteException; import org.apache.commons.io.FileUtils; /** * This file tries to eliminate the existing 'firefox' process * from java. It is an example. Change it into real java process * killer by adding parameters. extend it with windows cmd process * kill script etc.. * * @author diuw * */ public class JavaProcessKiller { private void run() { // Go for mysql(only current user process can be killed) String targetName = "firefox"; String line = "kill -9 `ps -ef | grep " + targetName + " | awk '{print $2}'`;"; // Create a tmp file. Write permissions!? try { FileUtils.writeStringToFile(new File("killProcess.bash" , line); // Execute the file we just creted. No flags are due if it is // executed with bash directly CommandLine commandLine = CommandLine.parse("bash killProcess.bash" ; try { DefaultExecutor executor = new DefaultExecutor(); executor.execute(commandLine); } catch (ExecuteException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } catch (IOException e1) { e1.printStackTrace(); } } public static void main(String[] args) { new JavaProcessKiller().run(); } }
|
TAGS
|
|
RELATED
|
Pages
Posts
|
|
SOCIAL
|


















