0

I made a simple program that kill a process when cpu usage is high.

public class Main {

public static void main(String[] args){
    try
    {
        if(SystemStatusReader.getCpu() < 50)
        {
            String startApp = "./standalone.sh 0.0.0.0 &";

           // Process pr = Runtime.getRuntime().exec("pgrep -u jboss java");
            Process pr = Runtime.getRuntime().exec("pidof top");
            BufferedReader read = new BufferedReader(new InputStreamReader(
            pr.getInputStream()));
            String str = read.readLine();
            System.out.println("Process id(s) to kill: " + str);
            String strKillPr = "kill -9 " + str;
            Process killPr = Runtime.getRuntime().exec(strKillPr);
        }

    }
    catch(Exception ex)
    {
        System.out.println(ex);
    }
}

}

The program works if it's running from terminal but when I try to run it from Crontab using

*/1 * * * * /usr/java/jdk1.7.0_45/bin/java -jar /usr/local/jboss-as-7.1.1.Final/bin/CpuChecker.jar

Also the jar file have the permission (chmod 777).

Anybody knows what I'm missing?

Jebus
  • 75
  • 1
  • 3
  • 12

0 Answers0