Information description and meaning of the corresponding file in the Linux/proc/pid directory

Source: Internet
Author: User

Proc is a virtual file system that is mounted on the/proc directory in a Linux system. Proc has several features, which include the ability for users to access kernel information or use it for troubleshooting, one of the most useful features that Linux has become more specific, and the ability to access process information in the form of text streams. Very Linux commands (such as PS, Toppstree, and so on) need to use this filesystem's information. Note that this article is to introduce users to some of the ways to access this information. It should be noted that the content described in this article does not necessarily apply to all kernel versions, and some operations are only available for the 2.6 kernel.
I. Process information
In the/proc file system, each process has a corresponding file. Here are some important files under the/proc directory:
The/proc/pid/cmdline contains the commands used to start the process;
/PROC/PID/CWD contains a link to the working directory of the current process;
/proc/pid/environ contains a list of the available process environment variables;
/proc/pid/exe contains the program links that are running in the process;
/proc/pid/fd/This directory contains a link to each file that the process opens;
/proc/pid/mem contains the contents of the process in memory;
/proc/pid/stat contains the status information of the process;
The/PROC/PID/STATM contains memory usage information for the process.
Here are some examples of getting process information:
Let's say now to see if all the processes are doing the memory cleanup work. Each process identity in the/proc/pid/stat file (the 8th attribute) provides a lot of "personal" information about the process. This information can be performed on each process identity.
0x00000002 Process being created
0x00000004 Exiting
0x00000008 Dead
0x00000040 Process using
Superuser Privflage
0x00000200 P rocess Dumping Core
0x00000400 Prooess received some signal
0x00000800 Process Allocating memory
0x00001000 killed due to out-of--memory condition
The author extracts this information from the/usr/src/linux/include/linux/sched.h.
The/proc/pid/fd/directory provides information about opening a file. To view the input files used by the process, use the following command:

ls–l/proc/pid/fd/0

To view the socket used by the process, use the following command:
#ls –l/proc/pid/fd|sed–n/socket/{s/.*<br/>//;s/<br/>//;s/<br/>//p}
Information about these sockets can be obtained using the following command:

Netstat--ae

To pass command-line arguments to any process, use the following command:
~~cat/proc/pid/cmdline
To get the ID number of the parent process for a process, use the following command:
#grep Ppid/proc/pid/status
Second, the general system Information
The proc contains a lot of system information, including CPU load, file system, and network configuration. Here are some examples of viewing and changing the system through Proc:
To get the space available for system memory:

grep free/proc/meminfo

System statistics since the last boot of the system can be obtained from the/proc/stat file:
#grep Processes/proc/stat
Learn the average of the system load for the 1th, 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 partition information for the system.
/proc/net and/proc/sys/net can be used to view and change important network information. For example, to disable the ping command, you can run the following command as root:
#echo 1>/proc/sys/net/ipv4/icmp_echo_ignore_all
Use the following command if you want to enable IP forwarding/IP spoofing:
#echo 1>/proc/sys/net/ipv4/ip_forward
File system information that has already been mounted can be retrieved from/proc/mounts.
To change the host name in use, use the following command:

Echo Www.abc.corn >/proc/sys/kernel/hostname

To obtain CPU information, use the following command:

Cat/proc/cpuinfo

To learn about the swap space usage, use the following command:

Cat/proc/swaps

To get the system uptime:
#cat/proc/uptime
List the file systems shared by NFS:

Cat/proc/fs/nfsd/exports

Third, the relevant core information
This is a very broad topic and only a few of them are covered here:
Learn the kernel version from the running kernel:
#cat/proc/version
The/proc/kmsg file is used as the kernel log information source, which can be invoked as an interface for system information.
The/proc/kcore file provides access to the system's physical memory as a kernel file format and can be used by GDB to check the current state of any kernel data structure. If the source code is installed, you can get more information by looking at the/usr/src/linux/documentation/filesystems/proc.txt file.
As can be seen from this, Proc is a very good access to the system information channels. If used well, it can provide a great help to the maintenance and management of Linux system.

"The meaning of each file"
/proc is a pseudo file system that is used as an interface for kernel data structures, not just an explanation of/dev/kmem.
Most of the files in/proc are read-only, but you can also change kernel variables by writing some files.
(
The Linux kernel provides a mechanism for accessing kernel internal data structures and changing kernel settings at run time through the/proc file system. The proc file system is a pseudo-file system that only exists in memory and does not occupy external memory space. It provides an interface for accessing system kernel data in a file system manner.

Users and applications can get system information through proc, and can change certain parameters of the kernel. Because the information of the system, such as the process, is dynamically changed, so when the user or application reads the proc file, the proc file system dynamically reads the required information from the system kernel and submits it. These files or subfolders listed below are not always present in your system, depending on your kernel configuration and the modules that are loaded. In addition, there are three important directories under/proc: NET,SCSI and Sys. The SYS directory is writable and can be used to access or modify kernel parameters, while net and SCSI depend on the kernel configuration. For example, if the system does not support SCSI, the SCSI directory does not exist.

In addition to the above, there are a number of directories named, they are the process directory. Each process currently running in the system has a corresponding directory under/proc, with the PID number of the process as the directory name, which is the interface to read the process information. The self directory is the information interface of the read process itself and is a link.

)

The following is a rough introduction to the entire/proc directory.

[NUMBER]
In the/proc directory, each running process has a subdirectory named after the process ID, which includes the following directories and pseudo-Files:
[Number]/cmdline
The file holds the full command line for the process. If the process has been swapped out of memory, or if the process is dead, then nothing is in the file, and the read operation on the file will return 0 characters. The file ends with a null character, not a line break.
[Number]/cwd
A symbolic connection that points to the current working directory of the process. For example, to find the CWD for process 20, you can:
CD/PROC/20/CWD; /bin/pwd
Note that the PWD command is usually built into the shell and may not work well in such a situation (Casper Note: pwd can only show/PROC/20/CWD, if you want to know its working directory, directly ls-al/proc/20 not good).
[Number]/environ
The file holds the environment variables for the process, separated by a null character, and possibly a null character at the end. Therefore, if you want to output the environment variables for process 1, you should:
(Cat/proc/1/environ; echo) | TR "; \000"; "; \ n";
(For the reasons why you want to do this, see Lilo (8).)
[Number]/exe
is also a symbolic connection, pointing to the binary code being executed. Under Linux 2.0 or earlier, the Readlink (2) of the EXE special file returns a string in the following format: [Device number]: node number
For example, [0301]:1502 is a 1502 node of a device with a main device number of 03 (such as IDE, MFM, etc.), from the device number 01 (the first partition of the first drive). Under Linux 2.2, Readlink (2) gives the actual path name of the command. In addition, the symbolic connection can be referenced normally (attempting to open an EXE file will actually open an executable file). You can even type/proc/[number]/exe to run a copy of the [number] process. The Find (1) command with the-inum option can locate the file.
[Number]/fd
Each file opened by the process has a symbolic connection to that subdirectory, named after the file descriptor, which is actually a symbolic connection to the real file (as with the EXE record). For example, 0 is the standard input, 1 is the standard output, 2 is the standard error, and so on. The program may sometimes want to read a file but do not want the standard input, or want to write to a file but do not want to send the output to the standard output, it is very effective to cheat (assuming-i is the input file's flag, and-O is the output file's flag):
Foobar-i/proc/self/fd/0-O/PROC/SELF/FD/1 ...
This is a filter that works. Please note that this method cannot be used to search the file because the files in the FD directory are not searchable. In UNIX-like systems,/proc/self/fd/n is basically the same as/dev/fd/n. In fact, most Linux Makedev scripts connect the/DEV/FD symbol to the [....] On the/PROC/SELF/FD.
]

Information description and meaning of the corresponding file in the Linux/proc/pid directory

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.