武威网站建设优化,给公司做网站 优帮云,零基础网站建设教学视频,哈尔滨比较好的设计公司我有一个问题,我需要从Java / groovy程序中找出Linux中进程的硬打开和软打开文件限制.当我从终端执行ulimit时,它将为硬打开文件限制和软打开文件限制提供单独的值.$ulimit -n1024$ulimit -Hn4096但是,如果我以常规方式执行它,它将忽略软限制并始终返回硬限制值.groovy [ba…我有一个问题,我需要从Java / groovy程序中找出Linux中进程的硬打开和软打开文件限制.当我从终端执行ulimit时,它将为硬打开文件限制和软打开文件限制提供单独的值.$ulimit -n1024$ulimit -Hn4096但是,如果我以常规方式执行它,它将忽略软限制并始终返回硬限制值.groovy [bash, -c, ulimit -n].execute().textResult: 4096groovy [bash, -c, ulimit -Hn].execute().textResult: 4096如果我缺少什么,请告诉我.我已使用ubuntu 12.04,Groovy版本1.8.4 JVM1.6.0_29来执行此操作.更新我在Java中尝试过同样的事情.import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.Reader;import java.io.StringWriter;import java.io.Writer;public class LinuxInteractor {public static int executeCommand(String command, boolean waitForResponse, OutputHandler handler) {int shellExitStatus -1;ProcessBuilder pb new ProcessBuilder(bash, -c, command);pb.redirectErrorStream(true);try {Process shell pb.start();if (waitForResponse) {// To capture output from the shellInputStream shellIn shell.getInputStream();// Wait for the shell to finish and get the return codeshellExitStatus shell.waitFor();convertStreamToStr(shellIn, handler);shellIn.close();}}catch (IOException e) {System.out.println(Error occured while executing Linux command. Error Description: e.getMessage());}catch (InterruptedException e) {System.out.println(Error occured while executing Linux command. Error Description: e.getMessage());}return shellExitStatus;}public static String convertStreamToStr(InputStream is, OutputHandler handler) throws IOException {if (is ! null) {Writer writer new StringWriter();char[] buffer new char[1024];try {Reader reader new BufferedReader(new InputStreamReader(is,UTF-8));int n;while ((n reader.read(buffer)) ! -1) {String output new String(buffer, 0, n);writer.write(buffer, 0, n);if(handler ! null)handler.execute(output);}} finally {is.close();}return writer.toString();} else {return ;}}public abstract static class OutputHandler {public abstract void execute(String str);}public static void main(String[] args) {OutputHandler handler new OutputHandler() {Overridepublic void execute(String str) {System.out.println(str);}};System.out.print(ulimit -n : );LinuxInteractor.executeCommand(ulimit -n, true, handler);System.out.print(ulimit -Hn : );LinuxInteractor.executeCommand(ulimit -Hn, true, handler);}}该程序的输出$java LinuxInteractorulimit -n : 4096ulimit -Hn : 4096为什么Java中的行为相同.是Java设置ulimit吗提前致谢.解决方法:Groovy正在其启动脚本中将此限制设置为最大.在startGroovy160中# Increase the maximum file descriptors if we can.if [ $cygwin false -a $darwin false ] ; thenMAX_FD_LIMITulimit -H -nif [ $? -eq 0 ] ; thenif [ $MAX_FD maximum -o $MAX_FD max ] ; thenMAX_FD$MAX_FD_LIMITfiulimit -n $MAX_FDif [ $? -ne 0 ] ; thenwarn Could not set maximum file descriptor limit: $MAX_FDfielsewarn Could not query businessSystem maximum filedescriptor limit: $MAX_FD_LIMITfifi事实证明,jvm自行设置了此限制.我不确定为什么groovy也会改变它.尝试java -XX:-MaxFDLimit LinuxInteractor它将禁用此行为.标签groovy,jvm,ulimit,linux,java来源 https://codeday.me/bug/20191101/1982240.html