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.

How can lsof report more open files than what ulimit says is the limit?

prod_web3(i-ca0b05aa):~$ sudo lsof | wc -l
4399
prod_web3(i-ca0b05aa):~$ ulimit -n
1024
share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

From the ulimit builtins man page

The ulimit builtin provides control over the resources available to the shell 
and to processes started by it on systems that allow such control.

Your lsof command lists all of the open files for all processes for all users on the system. You are not comparing like with like.

share|improve this answer
add comment

A bash(1) builtin, ulimit defines the maximum number of open files per process.

This is not a system-wide setting in any way.

share|improve this answer
add comment

Although this is old, I wanted to ask the same question... the answer is not satisfactory in my case as this is what happens:

$ sudo su tomcat -c "ulimit -n"
1024
$ lsof -u tomcat
3967

I'm not entirely sure why this happened. I guess that open files from sub process are not accounted for in the parent one.

share|improve this answer
    
The limit set by ulimit is per process and not per user. If you want to check the number of open file handles for a given process, use lsof -p $pid –  Tonin Mar 28 at 15:48
    
@Tonin I can't remember now exactly, but I'm pretty sure there was only one (main) process. Could it be that the limit applies also to subprocesses (same ppid)? Or perhaps there is some valve configuration that starts new processes instead of sub ones in tomcat... –  estani Apr 1 at 16:07
    
The limit value is inherited by child processes. But enforcement of the limit is done per process: the parent can have 1024 open files and the child can have 1024 open files too. I'm not sure about the number of processes tomcat has when running, it might depends on installation/configuration. –  Tonin Apr 1 at 16:19
add comment

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.