Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I type ulimit -n on my command line and get 1024 as the answer.

Then I run the following java program (attempting to prove open file limits):

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeoutException;

public class tester {
    public static void main(String[] args) throws IOException, TimeoutException, InterruptedException, Exception{
        List list = new ArrayList();
        int i = 0;
        for (i = 0; i < 5000; i++){
            try {
                FileInputStream is = new FileInputStream(new File("/tmp/test.txt"));
                InputStreamReader isr = new InputStreamReader(is);
                BufferedReader br = new BufferedReader(isr);

            catch(Exception e){
                System.out.println("Error on run: " + i);


Exceptions start getting thrown for too many files at 4096 files open. Shouldn't this number be 1024 or less? Are file limits for a user per process, or per account? (i.e. I can't open more than 1024 files per user no matter what processes I'm running, or each process can open as much as 1024 files.)


share|improve this question
You forgot to mention your distribution; generally there's a soft and a hard limit. Soft limit is what you see in ulimit's output. Hard limit is in e.g. /etc/sysctl.conf or /etc/security/limits.conf –  tink Jun 12 '13 at 19:07
ah yes, it is 4096 (ulimit -Hn). How does that work? Why is my soft limit allowed to be exceeded, and when will it be enforced? –  blefko Jun 14 '13 at 18:40
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.