ulimit nofiles and lsof

6

1

If I do an

lsof | grep user | wc -l

I get a number returned in the 25,000 range.

If I check

ulimit -a user

nofiles is set at 1024.

Can someone help me to understand the number of open files setting better? Clearly it's not the case, but I thought a hard nofiles of 1024 meant a user can't have more than 1024 open files.

HayekSplosives

Posted 2013-04-08T12:45:00.627

Reputation: 533

Answers

4

The file limit returned by ulimit is the number of files that can be opened by a single process (ulimit -n to only see number of descriptors). The value returned is the RLIMIT_NOFILE (or man getrlimit), described in man ulimit. This small application will output the same value (1024):

#include <stdio.h>
#include <sys/time.h>
#include <sys/resource.h>

int main(){
    struct rlimit info;
    getrlimit(RLIMIT_NOFILE, &info);
    printf("%d\n", info.rlim_cur);
    return 0;
}

Kristian Evensen

Posted 2013-04-08T12:45:00.627

Reputation: 151

Interesting. Thank you for busting out the source, it makes it much easier to understand how it plays out. – HayekSplosives – 2013-04-08T17:03:27.173

1Glad you found it helpful. Please accept the answer if you feel it is good enough :) – Kristian Evensen – 2013-04-08T19:34:51.973

2

You are probably counting a lot of duplicate files. Try

lsof -u <user> | grep "/" |sort -k9 -u | wc

which should filter out some of the non-file descriptors and the duplicate file entries. I stole this answer from an identical questions on Serverfault.

Jonathan Ben-Avraham

Posted 2013-04-08T12:45:00.627

Reputation: 936