linux ulimit with java does not work properly

后端 未结 1 1935
梦如初夏
梦如初夏 2021-01-28 02:03

I run code on linux ubuntu 17.10

public class TestExec {
public static void main(String[] args) {
    try {
        Process p = Runtime.getRuntime().exec(new Str         


        
相关标签:
1条回答
  • 2021-01-28 02:16

    You get the same result if you run the same command from the command line:

    $ "/bin/sh" "-c" "ulimit" "-n"
    unlimited
    

    This is because -c only looks at the argument immediately following it, which is ulimit. The -n is not part of this argument, and is instead instead assigned as a positional parameter ($0).

    To run ulimit -n, the -n needs to be part of that argument:

    $ "/bin/sh" "-c" "ulimit -n"
    1024
    

    In other words, you should be using:

    new String[]{"/bin/sh", "-c", "ulimit -n"}
    
    0 讨论(0)
提交回复
热议问题