我正在嘗試設置我的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
提交
取消