bash为什么ulimit通过java运行时返回不同的结果。行政长官()
为什么“ulimit-a”在运行时返回的结果不同。在bash下直接运行exec(),谢谢大家的指点
爪哇: 打开文件(-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();
}
# 1 楼答案
bash执行自己的ulimit命令?检查轮廓bashrc等
# 2 楼答案
ulimit
是一个shell内置项,其默认值基于shell的配置。Java可能使用的是除bash之外的默认shell。即使不是这样,也可能是您在.profile
中有一些设置,当您有命令行时会调用这些设置,但在以编程方式运行shell时不会调用这些设置