Linux/proc virtual file system

Source: Internet
Author: User
Tags high cpu usage
Linux/proc virtual file system the/proc directory on Linux is a file system, that is, the proc file system. Unlike other common file systems,/proc is a pseudo file system (virtual file system) that stores a series of special files in the current kernel running status, user... linux/proc virtual file system the/proc directory on Linux is a file system, that is, the proc file system. Unlike other common file systems,/proc is a pseudo file system (virtual file system) that stores a series of special files in the current kernel running status, you can use these files to view the system hardware and currently running processes, or even change the running status of the kernel by changing some of these files. Based on the particularity described above in the/proc file system, the files in it are also called virtual files and have some unique characteristics. For example, although some files return a large amount of information when you use the View command, the file size is displayed as 0 bytes. In addition, the time and date attributes of most files in these special files are generally the current system time and date, which is related to the refresh (stored in RAM) at any time. To facilitate viewing and usage, these files are usually stored in different directories and even subdirectories by relevance, for example, the/proc/scsi Directory stores information about all SCSI devices in the current system, and the/proc/N stores information about the processes currently running in the system, where N is a running process (as you can imagine, the related directory will disappear after a process ends ). Most virtual files can be viewed using file viewing commands such as cat, more, or less. some file information can be clearly expressed, but some file information is not readable. However, these files with poor readability can be well viewed using commands such as apm, free, lspci, or top. 1. process information in the/proc file system, each process has a corresponding file. Below are some important files in the/proc directory:/proc/pid/cmdline contains commands for starting processes; /proc/pid/cwd contains a link to the current process working directory;/proc/pid/environ contains a list of available process environment variables; /proc/pid/exe contains links to programs running in the process;/proc/pid/fd/this directory contains links to each file opened by the process; /proc/pid/mem contains the process content in the memory;/proc/pid/stat contains the process status information; /proc/pid/statm contains the memory usage information of the process. The following are examples of obtaining process information: The/proc/pid/fd/directory provides information about opening files. To view the input file used by the process, run the following command: ls-l/proc/pid/fd/0 to view the socket used by the process: ls-l/proc/pid/fd | sed-n'/socket/{s /. * \ [//; s/\] // p} 'information about these sockets can be obtained using the following command: netstat -- AE should pass the command line parameter to any process, run the following command: cat/proc/pid/cmdline: grep PPid/proc/pid/status 2. common system information Proc contains many system information, including CPU load, file system, and network configuration. The following is an example of how to view and change the system through Proc: Get the available system memory space: grep Free/proc/meminfo system statistics after the last system startup can be obtained from the/proc/stat file: grep processes/proc/stat average system load of 1st, 5, and 15 minutes: awk '{print "1 min: \ t" $1 "\ n5 min: \ t "$2" \ n15 min: \ t "$ 3'/proc/loadavg/proc/partitions can be used to obtain system partition information. /Proc/net and/proc/sys/net can be used to view and change important network information. For example, to disable the ping command, run the following command as root: echo 1>/proc/sys/net/ipv4/icmp_echo_ignore_all. to enable IP forwarding/IP spoofing, run the following command: echo 1>/proc/sys/net/ipv4/ip_forward file system information that has been mounted can be retrieved from/proc/mounts. To change the host name in use, run the following command: echo www. abc. corn>/proc/sys/kernel/hostname to obtain CPU information, run the following command: cat/proc/cpuinfo to know the usage of swap space: cat/proc/swaps get the normal running time of the system: cat/proc/uptime lists the file systems shared by NFS: cat/proc/fs/nfsd/exports 3. obtain the kernel version from the running kernel: the cat/proc/version/proc/kmsg file is used as the kernel log information source and can be used as an interface for calling system information. The/proc/kcore file allows you to access the physical memory of the system in the form of an inner-core file. gdb can be used to check the current status of any kernel data structure. If the source code is installed, you can view the/usr/src/linux/Documentation/filesystems/proc.txt file to obtain more information. It can be seen that Proc is a very good channel for obtaining system information. If it is well utilized, it can greatly help the maintenance and management of the Linux system. 4. An example of a simple application used to troubleshoot high CPU usage: execute the "top" command, for example, "mysqld" in the first line. I want to check the execution files and files opened, the corresponding PID is 29792. in the ls-l/proc/29792 graph, the blue cwd indicates the path of the application, and the blue exe indicates the name and location of the execution file, the blue fd directory lists the files opened by the application.
Related Article

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.