Re: [RFC] proc: report open files as size in stat() for /proc/pid/fd
From: Theodore Ts'o
Date: Sat Sep 17 2022 - 11:31:55 EST
On Fri, Sep 16, 2022 at 04:08:52PM -0700, Ivan Babrou wrote:
> We considered putting the number of open files in /proc/pid/stat.
> Unfortunately, counting the number of fds involves iterating the fdtable,
> which means that it might slow down /proc/pid/stat for processes
> with many open files. Instead we opted to put this info in /proc/pid/fd
> as a size member of the stat syscall result. Previously the reported
> number was zero, so there's very little risk of breaking anything,
> while still providing a somewhat logical way to count the open files.
Instead of using the st_size of /proc/<pid>/fd, why not return that
value in st_nlink? /proc/<pid>/fd is a directory, so having st_nlinks
return number of fd's plus 2 (for . and ..) would be much more natural.
Cheers,
- Ted