Analysis of proc in Linux

Source: Internet
Author: User

1. What is proc

Observing the Linux F8/etc/rc.d/sysinit file, you can see that the following statement appears in line 21 of the script:

if [!-e/proc/mounts]; Then    mount-n-T Proc/proc/proc    mount-n-t Sysfs/sys/sys >/dev/null 2>&1fi
This interruption means that if the/proc/mounts file exists, mount the proc device of the proc type file system to the proc directory, mount the file system of the SYSFS type to the/sys directory under the SYS device. So, what exactly is 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.

2. Main directories and files of the proc

Its main directory and file structure are as follows: (/proc/)

APM             # Advanced Power Management Information Bus             # Bus configuration information (USB configuration is also recorded here) cmdline         # kernel command line cpuinfo         # about CPU information Devices         # Devices that can be used (block devices/ Character device) DMA             # using DMA channel filesystems     # Supported file system interrupts      # interrupts using ioports         # I/O port use kcore           # kernel Core Impressions kmsg            # kernel message ksyms           # kernel symbol table LOADAVG         # Load Balancer Locks           # kernel lock meminfo         # Memory Info Misc            # Miscellaneous Modules         # Load Module list (can be thought of as driver) Mounts          # Loaded file system Partitions      # System-recognized partition table PCI             # on PCI bus, details of each device (can be viewed using LSPCI) RTC             # Real-time Clock slabinfo Slab   # Pool Info stat            # Full stats status table swaps           # Utilization of Swap Space         version # kernel versions Uptime          # System Uptime
In addition to the above directories, the PID numbers of the processes running on the host are also present in the/proc directory in the form of directory names. Where the CmdLine file and the Environ file are worth mentioning, the former represents the command string that initiates the process, and the latter is the content of the environment variable for the process. They can all be viewed using the cat command.

As shown in 1, process number No. 2088 is generated by the STARTX command, which is the current xwindows mode.


Figure 1

3. What is cmdline under the proc directory?

The following code appears in line 306 of the/etc/rc.d/sysinit script:

cmdline=$ (Cat/proc/cmdline)

It means assigning the contents of the/proc/cmdline to the cmdline variable. And the previous said that the content of/proc/cmdline refers to the kernel command line. Let's not dwell on what is the kernel command line and look at its contents. As shown in 2.

Figure 2

It can be found that the content is a discrete field. Obviously, these characters are generated by the kernel, which represents some basic information about the operating environment of the system, which is determined before the system is fully booted. These fields are like flag bits, so the subsequent start-up can be based on these "flag bits" to initiate the related operation.


so who produced it? Rough speaking, can be said to be generated by grub. the Grub (Grand Unified Bootloader) boot loader, which is the content that is read from the MBR of the first boot device after the computer has read the BIOS information. Without it, the core cannot be loaded onto the system at all. Grub has a lot of features, and we don't need to get into it for the moment. The kernel statement tells you where the MBR of the disk is going to read the system kernel and where the INITRD (Initalram disk) impression file is launched by the secondary system. You can also add some startup parameters, such as whether to open RHGB, whether to force the scan ... And these fields are all reflected in the kernel virtual file system/proc inside the cmdline inside.


Therefore, when we need to determine whether certain services are activated when the system is started, we should certainly look at the contents of/proc/cmdline.

Analysis of proc in Linux

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.