Why lsof report a higher open files number than ulimit's "open file" output
Asked Answered
T

3

6

Tomcat runs on my workstation for several days, now it has no response, lsof command outputs lots of close_wait state connections, tomcat pid is 25422, however the ulimit command shows that the "open file" is 1024, how can this happen?

[root@localhost home]# lsof -p 25422 | wc -l
10309

[root@localhost home]# ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 399360
max locked memory       (kbytes, -l) 32
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 399360
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited
Tonsure answered 4/11, 2013 at 9:23 Comment(2)
I have the some problem,do you find the possible reason?Stucker
See serverfault.com/q/396872 and superuser.com/q/579692 for some answersGutenberg
L
1

For open files, we have soft / hard open files limit on linux os.

If the soft limit is reached, it will just expand the limit to higher limit but under Hard limit.

By checking the hard limit, you can simply run:

# ulimit -Hn

Here is also an article that may help you understand more:

Guide to limits.conf / ulimit /open file descriptors under linux

Levkas answered 4/12, 2014 at 8:56 Comment(0)
R
1

Not every type of entry in lso counts towards ulimit. RUn the following command for getting only those fds that count towards ulimit

lsof -p <pid> -d '^cwd,^err,^ltx,^mem,^mmap,^pd,^rtd,^txt' -a
Recuperate answered 26/10, 2019 at 2:59 Comment(0)
S
0
  1. Lsof Options in Linux man page describes the command as follows:

In the absence of any options, lsof lists all open files belonging to all active processes.

enter link description here

  1. Ulimit simply limits resources at the user level,and applied to each process .That's why you see that the number in the Lsof report is far greater than that of the ulimit.

  2. If you want to get kernel level restrictions, use the following command

cat /proc/sys/fs/file-max

You'll get a very big number.

In summary, lsof may be more than ulimit , and it is definitely less than file-max.

Sorbitol answered 21/2, 2021 at 8:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.