[英]Alternative to “lsof” command in Linux
I need a command in Linux(SUSE & RHEL) to find the list of open files as "lsof" command is taking time to give output.Even "lsof -n" command also takes a lot of time. 我需要在Linux中使用命令(SUSE&RHEL)来查找打开文件的列表,因为“ lsof”命令要花一些时间才能输出。即使“ lsof -n”命令也要花费很多时间。 Do we have any alternative command to "lsof"? 我们是否可以使用其他命令代替“ lsof”?
Thanks, Sanghamitra 谢谢,Sanghamitra
You can read the open files from the proc file system. 您可以从proc文件系统中读取打开的文件。
for p in /proc/{0..9}*; do
i=$(basename "$p")
for f in "$p"/fd/*; do
l=$(readlink -e "$f")
if [ "$l" ]; then
echo "$i: $l"
fi
done
done | sort -u | sort -n
In short, use lsof -n
. 简而言之,请使用lsof -n
。
lsof
waits a lot because lsof
等待很多,因为
/dev
它花费大量时间来扫描/dev
所有设备 0.0.0.0
), and querying for them results timeout. 其中许多没有有效的revdns(如0.0.0.0
),并且查询结果超时。 You can give it a significant acceleration by disabling the dns resolution part with a -n
. 通过使用-n
禁用dns解析部分,可以大大提高它的速度。
Anyways, extending @ceving 's answer, you could also watch not only the list of the opened file descriptors, but also the list of the files mapped into the address space of the processes ( cat /proc/<pid>/map
). 无论如何,扩展@ceving的答案,您不仅可以查看打开的文件描述符的列表,还可以查看映射到进程地址空间( cat /proc/<pid>/map
)的文件的列表。
Typically, if you have a process running surprisingly slowly, a 通常,如果您的进程运行异常缓慢,
strace -f -tt -o sux <your command line>
will dump into the file sux
the kernel calls what the process did, with timestamps. 它将使用时间戳将内核执行的操作转储到文件sux
。 In essence, so you will be able to track, what exactly this process did and how long . 从本质上讲,您将能够跟踪到此过程的确切执行时间以及持续时间 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.