返回不同的結果爲什麼'ulimit -a'通過Runtime.exec()以不同的方式返回,直接在bash下運行它,感謝任何指針。爲什麼ulimit通過java Runtime.exec()
的Java: 打開文件(-n)65536
的bash-3.00 $的ulimit -a: 打開文件(N)256
public class TestUlimit {
public TestUlimit() throws IOException, InterruptedException {
Runtime runTime = Runtime.getRuntime();
Process p = runTime.exec(new String[] { "bash", "-c", "ulimit -a" });
InputStream in = p.getInputStream();
InputStreamReader isr = new InputStreamReader(in);
BufferedReader br = new BufferedReader(isr);
String line = null;
System.out.println("Result of Process p = runTime.exec(new String[] { \"bash\", \"-c\", \"ulimit -a\" });");
while ((line = br.readLine()) != null) {
System.out.println(line);
}
p.waitFor();
p = runTime.exec("ulimit -a");
in = p.getInputStream();
isr = new InputStreamReader(in);
br = new BufferedReader(isr);
System.out.println("Result of p = runTime.exec(\"ulimit -a\");");
while ((line = br.readLine()) != null) {
System.out.println(line);
}
p.waitFor();
}
幾乎不是Java的問題。 – EJP 2011-05-31 03:02:39
將絕對路徑添加到ulimit以確保您正在執行正確的路徑,例如/ bin/uname – 2011-05-31 07:55:57