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
Who manages CI environment in your enterprise?
- We don't use CI (92%, 11 Votes)
- Dedicated person per team, teams decide on their own (8%, 1 Votes)
- Everyone who can (0%, 0 Votes)
- Employee, single Release or Config Manager (0%, 0 Votes)
- Contractor, single Release or Config Manager (0%, 0 Votes)
- Team, Release or Config Management (0%, 0 Votes)
- External partner manages our CI (0%, 0 Votes)
- Different answer (0%, 0 Votes)
Total Voters: 12
Loading ...
Most popular search terms:
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
|


















