Utilitaires
Scripts
Divers
Jeux
Rechercher
Quillevere.net
Computer techniques

Number of opened/openable files on Linux

07/05/2022
On Linux as on Windows, there are thresholds fixing the number of files open simultaneously per process and for the whole system. Here are some commands to display them.

If too many files are open on a system, errors may occur, preventing the opening of a database, the call to a URL, etc. It is therefore necessary to ensure that this number remains below the maximum threshold.

Number of openable files on the system

The sysctl utility displays operating system settings. The file-max variable indicates the maximum number of files open by all processes.

sysctl fs.file-max

Number of openable files per process

The ulimit utility displays the limits set by process. The "open files" field contains the maximum number of open files per process.

ulimit -n

Number of opened files per user

The lsof utility displays details about open files. By counting the number of lines in the response, we get the number of opened files.

lsof -u <identifiant_utilisateur> | wc -l

Display continuously the number of opened files for a specific process

This command line continuously displays, with a 10-second pause, the number of files opened by each Java process. If there are several Java processes, this creates as many corresponding columns:

while true ; do echo -n "$(date '+%F %H:%M:%S')" ; for j in `pidof java`; do nb=$(lsof -w -p ${j} | wc -l); echo -e -n "\tPID ${j}=${nb}" ; done; echo ; sleep 10 ; done

If the lsof utility is not available, it can be replaced by the following command which returns essentially the same values:

ls /proc/<process_id>/fd/

Show the largest opened files

Shows the 10 largest opened files, sorted in descending order of size, excluding deleted files:

lsof -a / | tail -n +2 | grep ' REG ' | grep -v ' DEL ' | awk '{ print $7,"("$7/1048576 " Mo)",$9 }' | sort -t ' ' -k 1 -V -r | uniq -u | head -10

Add "-u myuser" after lsof to limit execution to a specific user's files.

This script can be tested by simulating an opened file (it redirects the output to a file then increase its filesize to 200 megabytes):

cat > test.eq &
truncate -s 200M test.eq
Dernière modification le 13/06/2023 - Quillevere.net

Commentaires

No inscription needed if you wish to

Search in this website

fr en rss RSS info Informations