tags:

views:

141

answers:

2

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

A: 

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

BalusC
I have tried to print error but I didnot get any error. I gor exited status 127
Deepak
+3  A: 

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.

Kilian Foth
thnx Kilian Forth, for your response
Deepak