返回不同的结果为什么'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