Tracking the number of files opened in Linux and solutions
Source: Internet
Author: User
During the issue investigation of ccpstoomanyopenfiles of The O2 project, there were a lot of problems. I just did a test: 1, how to view the number of files opened by the current process (this number fluctuates in real time) the following uses ccps as an example to describe 1) obtain the PID (process number) ps corresponding to the program...
During the issue investigation of ccps too program open files of the O2 project, there were a lot of problems. I just did a test: 1, how to view the number of files opened by the current process (this number fluctuates in real time) the following uses ccps as an example to describe 1) obtain the PID (process number) corresponding to the program) ps-ef | grep ccps execution [root @ vvmocmp1 ccps] # ps-ef | grep ccpsroot 5661 1 0 00:00:00 pts/2/bin/sh/opt/OC/ccps/jboss-4.2.3.GA /bin/run. sh-c all-g ccpsgroup-B 0.0.0.0 www.2cto.com root 5685 5661 94 20:33 pts/2 00:00:17/usr/java/jdk1.6.0 _ 13/bin/java-Dprogram. name = run. sh-se Rver-Dcom. sun. management. jmxremote-Djava. awt. headless = true-Xms1024m-Xmx1024m-XX: PermSize = 64 m-XX: MaxPermSize = 256 m-Djava. util. logging. config. file =/opt/OC/ccps/jboss-4.2.3.GA/server/all/ccps/applicationContext/logging. properties-Xrunjdwp: transport = dt_socket, address = 8787, server = y, suspend = n -Djava.net. prefer12004stack = true-Djava. endorsed. dirs =/opt/OC/ccps/jboss-4.2.3.GA/lib/endorsed-classpath /Opt/OC/ccps/jboss-4.2.3.GA/server/all/ccps/applicationContext:/opt/OC/ccps/jboss-4.2.3.GA/bin/run. jar:/usr/java/jdk1.6.0 _ 13/lib/tools. jar org. jboss. main-c all-g ccpsgroup-B 0.0.0.0 from the perspective that the current ccps process owner is root and pid is 5685.2) use the obtained pid number, to obtain the number of files opened by this process in real time ls-l/proc/5685/fd/| wc-l www.2cto.com (note: The lsof-p pid is used on the Internet, the number of files opened by the process can be queried. However, the experiment does not show the accuracy of the real-time response. when the value of ulimit-n is exceeded, the too program open files error will immediately occur) at the same time, the root user is also subject to uli You can use ulimit-n to view the limit of the current user in the current session. the default value is 10242. you can view the maximum number of opened files of the current user process (the default value of ulimit-n is 1024 ), you can also use limit-a to view [root @ vvmocmp1 ~] # Ulimit-acore file size (blocks,-c) 0 data seg size (kbytes,-d) unlimitedfile size (blocks,-f) unlimitedpending signals (-I) 1024max locked memory (kbytes,-l) 32max memory size (kbytes,-m) unlimitedopen files (-n) 1024 pipe size (512 bytes,-p) 8 POSIX message queues (bytes,-q) 819200 stack size (kbytes,-s) 10240cpu time (seconds,-t) unlimitedmax user processes (-u) 143359 virtual memory (kbyt Es,-v) unlimitedfile locks (-x) unlimited www.2cto.com 3. modify the maximum number of opened files in/etc/security/limits. added to the conf file, root soft nofile 500 root hard nofile 500 Note: The purpose of this experiment is to make the root ccps process appear too open files. it is intentionally very small. 500 because the ccps owner is root, the root user is set. After setting, you need to log on to the server as the root user again. The modification takes effect now. you can use ulimit-n to view 4. you must start ccps in the session that is logged on again in step 3, in this way, an error occurs when the number of files opened at the same time in ccps exceeds 500. [Root @ vvmocmp1 ccps] # tail-f. /log/ccps. logat org. springframework. util. methodInvoker. invoke (MethodInvoker. java: 270) at org.springframework.scheduling.quartz.methodinvokingjobdetailfactorybean?methodinvokingjob.exe cuteInternal (MethodInvokingJobDetailFactoryBean. java: 224) at org.springframework.scheduling.quartz.QuartzJobBean.exe cute (QuartzJobBean. java: 86) at org. quartz. core. jobRunShell. run (JobRunShell. java: 203) at org. quartz. simpl. simpleThreadPool $ WorkerThread. run (SimpleThreadPool. java: 520) Caused by: java. io. IOException: java. io. IOException: error = 24, Too enabled open filesat java. lang. UNIXProcess. (UNIXProcess. java: 148) at java. lang. processImpl. start (ProcessImpl. java: 65) at java. lang. processBuilder. start (ProcessBuilder. java: 452 )... 13 more [12-22 20:38:20, 564] WARN [DefaultQuartzScheduler_Worker-8] SystemResourceMonitor. updateDiskInfoMap (826) | Can't execute "/bin/df-lP/var/opt/OC/ccps/cdr/local/" command www.2cto.com java. io. IOException: Cannot run program "/bin/df": java. io. IOException: err Or = 24, Too implements open filesat java. lang. processBuilder. start (ProcessBuilder. java: 459) at java.lang.Runtime.exe c (Runtime. java: 593) at java.lang.Runtime.exe c (Runtime. java: 431) at java.lang.Runtime.exe c (Runtime. java: 328) at com. hp. opencall. ccps. ccs. performance. systemResourceMonitor. updateDiskInfoMap (SystemResourceMonitor. java: 824). at this time, ls-l is about 500, while lsof-p is used to view more than 800 without errors. [Root @ vvmocmp1 ccps] # ls-l/proc/5685/fd/| wc-l489
Note: After testing, you must remove the two rows added above.
By RogerZhuo
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