Linux File and File Descriptor Information: Difference between revisions
Line 7: | Line 7: | ||
* [[Ls#ls_and_File_Time_Information|<tt>ls</tt> and File Time Information]] | * [[Ls#ls_and_File_Time_Information|<tt>ls</tt> and File Time Information]] | ||
=File Descriptors | =File Size= | ||
==File Size with <tt>wc</tt>== | |||
==File Size with <tt>stat</tt>== | |||
==File Size with <tt>du</tt>== | |||
==File Size with <tt> find </tt>== | |||
=File Descriptors= | |||
There's a ''per-process'' maximum number of allowed [[Linux_General_Concepts#File_Descriptor|file descriptors]] - that can be set on a per-user basis - and a ''per-system'' limit. | There's a ''per-process'' maximum number of allowed [[Linux_General_Concepts#File_Descriptor|file descriptors]] - that can be set on a per-user basis - and a ''per-system'' limit. |
Revision as of 02:58, 25 December 2020
External
- http://www.netadmintools.com/art295.html
- http://www.cs.wisc.edu/condor/condorg/linux_scalability.html
Internal
File Size
File Size with wc
File Size with stat
File Size with du
File Size with find
File Descriptors
There's a per-process maximum number of allowed file descriptors - that can be set on a per-user basis - and a per-system limit.
For more information about file descriptors see:
Number of Allowed File Descriptors
Allowed File Descriptors Per System
cat /proc/sys/fs/file-max
To change it:
echo "200000" > /proc/sys/fs/file-max
or set the following in /etc/sysctl.conf:
fs.file-max = 200000
Allowed File Descriptors Per Process
ulimit -n
To change it: ulimit - Set a Value.
More on ulimit:
Number of Used File Descriptors
Used File Descriptors per System
cat /proc/sys/fs/file-nr
The results show, in order: total allocated open file descriptor, total free allocated file descriptors, maximum.
Used File Descriptors per Process
The number of opened file descriptors per process can be inferred by listing the content of /proc/<pid>/fd directory. This directory contains links representing the open file descriptors of the process in question and the files they represent:
ls -l /proc/<pid>/fd
total 0 lr-x------. 1 vagrant vagrant 64 May 3 09:45 0 -> /dev/null lrwx------. 1 vagrant vagrant 64 May 3 09:45 1 -> /dev/pts/0 (deleted) ...
The number of open file descriptors can be obtained with:
ls -l /proc/<pid>/fd | wc -l
and subtract 1 from it (discard "total 0" line).
Information about a specific open file is provided in the /proc/<pid>/fdinfo/<fd> files. A typical fdinfo file contains a "pos" field, which represents the current offset of the opened file in decimal form and "flags" which is the octal O_xxx mask the file has been created with.
The contents of /proc/<pid>/fd and /proc/<pid>/fdinfo are in sync.
Open Files
All files opened on the system can be obtained with:
lsof
All files opened by one process can be obtained with:
lsof -p <pid>
Note that the output of lsof includes all information that can be obtained by listing the /proc/<pid>/fd directory, and also other files that have a special significance for the process and are not associated with file descriptors, such as the current working directory, the root directory, memory mapped files, etc.
More about lsof: