The issue is i want to kill a process only if its running, otherwise i want to do something else.
This is my code right now (sublime as an example):
try {
Process p = Runtime.getRuntime().exec("pidof sublime_text");
if (p != null){
Runtime.getRuntime().exec("pkill -f sublime");
}
}
catch (Exception e) {
System.out.println(e.getMessage());
}
Runtime.getRuntime().exec("pidof sublime_text");
ALWAYS returns a process, even if this one doesn't exist, i mean, i can execute: Runtime.getRuntime().exec("pidof nonExistingProcess");
and this will still return a process without error, and then the kill "pkill" command
Runtime.getRuntime().exec("pkill -f nonExistingProcess");
doesn't throw an Exception either, what can i do?