bingooyong / note

1 stars 1 forks source link

玩转Inode文件打开连接数 #56

Open bingooyong opened 1 year ago

bingooyong commented 1 year ago

文件打开树

查看进程打开文件

# 先找出这个进程的ID号,使用下面的命令
ps -ef |grep jetty|awk '{print $2}'
# 然后根据这个进程ID号,统计出这个进程打开的文件数量
lsof -p PID | wc -l

修改CentOS系统默认的文件数量

# 打开文件/etc/security/limits.conf文件,追加下面两行内容:
* soft nofile 65535
* hard nofile 65535
bingooyong commented 1 year ago

how to check open file without lsof

Poor man's lsof is to execute

ls -l  /proc/[process id]/fd

Still, you need to be root.

bingooyong commented 1 year ago

查看最高限制数:

cat /proc/sys/fs/file-max

Linux:同时打开文件个数的限制,不同系统,限制也不同。

bingooyong commented 1 year ago

Show network connections of a process

lsof -i -a -p $(pidof firefox)

Try

lsof -i -a -p $(pidof firefox) From man page:

-i This option selects the listing of files any of whose Internet address matches the address specified in i. If no address is specified, this option selects the listing of all Internet and x.25 (HP-UX) network files. -a AND -p This option excludes or selects the listing of files for the processes whose optional Process IDentification (PID) numbers are in the comma-separated set s - e.g., 123 or 123,^456. (There should be no spaces in the set.)

bingooyong commented 1 year ago

How to determine the socket connection up time on Linux

find /proc/$pid/fd -lname "socket:\[$inode\]" -printf %t