crontab不运行jar文件

时间:2015-11-03 19:07:51

标签: jar crontab kill-process

我创建了一个简单的程序,当cpu使用率很高时会终止进程。

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);
    }
}

}

如果程序从终端运行但是当我尝试使用

从Crontab运行它时程序可以正常工作
  

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

jar文件也有权限(chmod 777)。

有人知道我错过了什么吗?

0 个答案:

没有答案
相关问题