首页 > 解决方案 > linux。调用 sys_clone 时的许多文件描述符

问题描述

我使用带有标志 SIGCHLD 的克隆创建 400 个线程 | 克隆_FS | 克隆文件 | 克隆_SIGHAND | 克隆虚拟机

和$ losf | wc -l 运行后显示 600 000 个打开的描述符

我需要做什么?

标签: c++linuxclone

解决方案


If you're using CLONE_FILES you probably don't need to do anything.

lsof shows the sum of file descriptors held by each thread, even though these different threads are sharing a single set of file descriptors on the backend. So if you have a 1000 threads with 100 file descriptors shared, it will appear to be 100,000 file descriptors open if you just check with lsof.

Check /proc/sys/fs/file-nr to see the actual number of file descriptors your system has open.

As for whether a tool exists that can determine a list of unique file descriptors and what processes/threads have them open, I'm not sure. I've never needed to do that myself, but it appears to be a problem no one has yet scratched.


推荐阅读