我正在尝试设置我的java程序运行的ulimit。目前,似乎ulimit -n设置为4096,因为当我运行此代码(这是我的java程序的一部分)时,它输出4096。ProcessBuilder processBuilder = new ProcessBuilder("/bin/bash", "-c", "ulimit -n");try { Process process = processBuilder.start(); // Prints 4096. LOGGER_.info(getStringFromInputStream(process.getInputStream()));} catch (IOException e) { // The flow does not reach this catch block. LOGGER_.error("exception caught: " + e.getMessage());}是否可以将其更改为其他内容,例如8192?我试过这个:ProcessBuilder processBuilder2 = new ProcessBuilder("/bin/bash", "-c", "ulimit -n 8192");try { Process process = processBuilder2.start(); LOGGER_.error("starting agent2..."); LOGGER_.error(getStringFromInputStream(process.getInputStream()));} catch (IOException e) { LOGGER_.error("exception caught2: " + e.getMessage());}和try { String[] cmdString = new String[3]; cmdString[0] = "/bin/bash"; cmdString[1] = "-c"; cmdString[2] = "ulimit -n 8192"; Process process = Runtime.getRuntime().exec(cmdString); LOGGER_.error(getStringFromInputStream(process.getInputStream()));} catch (IOException e) { LOGGER_.error("exception caught:" + e.getMessage());}但我不确定这些是否是正确的方法。此外,如果 ulimit -n 甚至被修改了。
添加回答
举报
0/150
提交
取消