1

I am using Fedora linux where ulimit -n 10000 increases file limit upto 10000. I want to achieve the same using java program

How to write java program to increase file limit using ulimit I have tried with the below program but it didnot work well. The program didnot give any error. but didnot increase file limit also

public class IncreaseFIle {
    public static void main(String[] args) {

       String command = "/bin/bash ulimit -n 10000";
//        String command = "pwd";
        try {
            Runtime.getRuntime().exec(command);

        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}

Thanks Sunil Kumar Sahoo

3
  • What's with the infinite loop? Commented May 19, 2010 at 13:12
  • 1
    Next time please format your code properly with the 101010 button. Commented May 19, 2010 at 13:12
  • That's not the cause of the problem but don't you need to be root for that? Commented May 19, 2010 at 13:35

2 Answers 2

5

From the man page:

The ulimit utility shall set or report the file-size writing limit imposed on files written by the shell and its child processes.

You java program is not the shell or one of its child process - it is the ancestor process, and therefore is unaffected by anything that its child process does. To get another ulimit you must somehow contrive to call ulimit before java is started.

Sign up to request clarification or add additional context in comments.

1 Comment

thnx Kilian Forth, for your response
0

The program did not give any error.

Indeed, you're ignoring any result. You need to get hold of the returned Process object and read its getInputStream() and getErrorStream() (which returns the program's stdout and stderr respectively). This information should tell more about the cause of the problem and understanding the cause should lead to the solution.

Check this article (all the 4 pages!) to learn how to use Runtime#exec() properly:
When Runtime.exec() won't

1 Comment

I have tried to print error but I didnot get any error. I gor exited status 127

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.