Background:
When we develop Linux online server, we often encounter problems with handle leaks. Because in the Linux system design, everything follows the principle of files, that is, disk files, directories, network sockets, disks, pipes, etc., all of which are files. When we open it, we will return an fd, which is a file. Handle. If you open a file frequently, or open a network socket and forget to release it, there will be a leak of the handle. In Linux system, the number of file handles that a process can call is limited. By default, the maximum number of handles that can be called by each process is 1024. If this limit is exceeded, the process will not be able to obtain a new handle, but will cause You cannot open a new file or network socket, and the service will be rejected for the online server.
View and modify the handle:
In the Linux system, you can view the maximum number of handles per process limit by ulimit–n, and modify the maximum number of handles of the process by ulimit –HSn 10240. When the number of handles reaches the limit, it will appear ”too many files open”.
There are several ways to view the number of handles occupied by a process:
1) You can view the thread whose thread pid number is open by using cat/proc/pid/fd;
2) With the lsof command, the /usr/sbin/lsof-p 21404 command results are as follows:
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAMEvas 21404 root cwd DIR 8,3 4096 30195729 /home/users/root /vasvas 21404 root rtd DIR 8,2 4096 2 /vas 21404 root txt REG 8,3 112201650 30195914 /home/users/root/vasvas 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.sovas 21404 root mem REG 8,2 1493186 339367 /lib64/tls/libc-2.3.4.sovas 21404 root mem REG 8,2 17943 339392 /lib64/libdl-2.3.4.sovas 21404 root mem REG 8,2 613297 339369 /lib64/tls/libm-2.3.4.sovas 21404 root mem REG 8,2 79336 490463 /usr/lib64/libz.so.1.2 .1.2
COMMAND: Name of the process PID: Process Identifier USER: Process Owner FD: File Descriptor, the application identifies the file by file descriptor. Such as cwd, txt, etc. TYPE: file type, such as DIR, REG, IPV4, FIEO, etc. DEVICE: Name of the specified disk SIZE: Size of the file NODE: Index node (identification of the file on the disk) NAME: The exact name of the open file < Br>
In addition, the lsof command can also view the process that occupies the port:
/usr/sbin/lsof-i :9001
Understand the process: ? PID, PPID? Current process status? Memory allocation? CPU and actu
Lab environment: Under Vbox, Rehat5 virtual machine Using samba server Purpose: Upload file to serv
ls is simply a list of file names in the directory, ll more detailed list of file types, file owner
Speaking of the easiest way to install the system is to find a system installation CD and then slowl
Build an Android environment on Ubuntu and download APKs from Google Play
Linux switch command (shutdown, reboot, halt, init)
The server does not support the curl
Linuxshell implements script to automatically clean up rman backup files
The difference between the linux command su and su- The maximum essential difference between the
Linux adds sudo rights to ordinary users
Linux ulimit command usage parsing
Nginx installation on Linux (CentOS)
CentOS open port 80, 8080 or open a port
Microsoft updated a series of core Win8 applications: greet Win8 RP version
Win7 partition method detailed illustration tutorial
Win8 enters the traditional interface skills when it starts up
Prohibit Win7 sloshing to help you save system resources [Figure]
Win10 taskbar how to add icons? Win10 taskbar to add a tutorial to display the desktop icon
How to cancel Win7 display Windows error recovery interface
Hard disk installation 32/64 bit Windows 2008 system method
How to use Win7's own tools to make dynamic photo albums
Select the details of the computer motherboard can not be ignored