Take the 2-minute tour ×
Server Fault is a question and answer site for 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);
                //System.out.println(br.readLine());

                list.add(is);
            }
            catch(Exception e){
                System.out.println("Error on run: " + i);
            }
        }
        System.out.println(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.)

Thanks!

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

1 Answer 1

Elaborating on Tink's comment;

For modern Red Hat Enterprise Linux (RHEL) & similar Linux distributions, /etc/security/limits.conf is where file-open, process-open and other such limits are defined.

There are 'soft' limits are basically "defaults" that all user's would receive. Any 'hard' limits are kernel-enforced, and are the absolute max for a given user.

I would recommend reading all documentation for that configuration file prior to any modification

From the RHEL 5 limits.conf man page

hard   for enforcing hard resource limits. These limits are set by the
       superuser and enforced by the Kernel. The user cannot raise his
       requirement of system resources above such values. 

soft   for enforcing soft resource limits. These limits are ones that the
       user can move up or down within the permitted range by any
       pre-exisiting hard limits. The values specified with this token can
       be thought of as default values, for normal system usage.

-      for enforcing both soft and hard resource limits together.

       Note, if you specify a type of '-' but neglect to supply the item and
       value fields then the module will never enforce any limits on the
       specified user/group etc.
share|improve this answer

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.