Linux handle leakage check, linux handle Leakage

Source: Internet
Author: User

Linux handle leakage check, linux handle Leakage
Background:

We often encounter handle leaks when developing linux Online servers. In the linux system design, everything follows the principle that everything is a file, that is, disk files, directories, network sockets, disks, pipelines, and so on. All these are files, when we open the file, an fd is returned, that is, the file handle. If files are frequently opened, or network sockets are opened and you forget to release them, the handle is leaked. In linux, the number of file handles that a process can call is limited. By default, the maximum number of handles that a process can call is 1024. If this limit is exceeded, A process cannot obtain a new handle, but cannot open a new file or network socket. A service is rejected on an online server.

View and modify the handle:

In linux, you can use ulimit-n to view the maximum number of handles restricted by each process, and use ulimit-HSn 10240 to modify the maximum number of handles of a process. When the number of handles reaches the limit, "too program files open" is returned ".

There are several methods to view the number of handles occupied by a process:

1) You can use cat/proc/pid/fd to view the thread opened by the thread pid;

2) run the/usr/sbin/lsof-p 21404 command through the lsof command. The result is as follows:

COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
Vas 21404 root cwd DIR 8, 3 4096 30195729/home/users/root/vas
Vas 21404 root rtd DIR 8, 2 4096 2/
Vas 21404 root txt REG 112201650 30195914/home/users/root/vas
Vas 21404 root mem REG 0 0 [heap] (stat: No such file or directory)
Vas 21404 root mem REG 105080 339377/lib64/ld-2.3.4.so
Vas 21404 root mem REG 1493186 339367/lib64/tls/libc-2.3.4.so
Vas 21404 root mem REG 17943 339392/lib64/libdl-2.3.4.so
Vas 21404 root mem REG 613297 339369/lib64/tls/libm-2.3.4.so
Vas 21404 root mem REG 79336 490463/usr/lib64/libz. so.1.2.1.2

COMMAND: process name
PID: process identifier
USER: process owner
FD: file descriptor. The application identifies the file through the file descriptor. Such as cwd and txt
TYPE: file TYPE, such as DIR, REG, IPV4, and FIEO
DEVICE: Specify the disk name.
SIZE: File SIZE
NODE: Index NODE (the identifier of the file on the disk)
NAME: the exact NAME of the opened file.

In addition, you can view the processes that occupy the port through the lsof command:

/Usr/sbin/lsof-I: 9001

 


Linux handle count

First, determine the PID of the java program, pidof java
Then go to the/proc/'pidof Java'/fd directory and check the number of opened file handles in wc-l.

How does one view the opened file handle in linux?

Ls-al ls-I

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.