Linux Handle Disclosure Problem view

Source: Internet
Author: User

Background:

When we develop Linux online server, we often encounter the problem of handle leaking. Because in the Linux system design to follow everything is the principle of the document. That is, disk files, folders, network sockets, disks, pipelines, and so on, all of which are files. When we open it we return an FD, which is the file handle.

If you open the file frequently, or open a network socket and forget to release it, there will be a handle leak. The number of file handles that a process can invoke is limited in the Linux system. By default, the maximum number of handles that each process can invoke is 1024. Assuming that the limit is exceeded, the process will not be able to get a new handle, and the service is rejected for the online server because the new file or network socket cannot be opened.

To view and change handles:

The maximum number of handles per process limit can be viewed through ulimit–n in a Linux system, using ULIMIT–HSN 10240 to change the maximum handle count of the process.

When the number of handles reaches the limit, the "too many files open" appears.

There are several ways to see how many handles a process occupies:

1) through CAT/PROC/PID/FD can view thread PID number open threads;

2) through the lsof command,/usr/sbin/lsof-p 21404 command results such as the following:

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 8,3 112201650 30195914/home/users/root/vas
Vas 21404 root mem REG 0,0 0 [heap] (Stat:no such file or directory)
Vas 21404 root mem REG 8,2 105080 339377/lib64/ld-2.3.4.so
Vas 21404 root mem REG 8,2 1493186 339367/lib64/tls/libc-2.3.4.so
Vas 21404 root mem REG 8,2 17943 339392/lib64/libdl-2.3.4.so
Vas 21404 root mem REG 8,2 613297 339369/lib64/tls/libm-2.3.4.so
Vas 21404 root mem REG 8,2 79336 490463/usr/lib64/libz.so.1.2.1.2

COMMAND : The name of the process  
PID: Process identifier
User: All users of the process
FD: A descriptive descriptor of a file. The application recognizes the file through a file description descriptor.

Such asCWD,txtwait 
TYPE: File types, such asDIR,REG,IPV4,FIEOwait 
DEVICE: Specifies the name of the disk 
SIZE: The size of the file 
NODE: Index node (the identity of the file on disk)
NAME: Open the exact name of the file

In addition, the lsof command is also able to view the process that occupies port:

/usr/sbin/lsof-i: 9001

Linux Handle Disclosure Problem view

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.