Showing posts with label Proc. Show all posts
Showing posts with label Proc. Show all posts

Tuesday, January 17, 2012

Explore Linux /proc File System (/proc directories, /proc files)


Inside the /proc directory, you’ll see two types of content — numbered directories, and system information files.
/proc is not a real file system, it is a virtual file system. For example, if you do ls -l /proc/stat, you’ll notice that it has a size of 0 bytes, but if you do “cat /proc/stat”, you’ll see some content inside the file.
Several Linux commands access the information from /proc, and displays in a certain format.

1. /proc Directories with names as numbers

Do a ls -l /proc, and you’ll see lot of directories with just numbers. These numbers represents the process ids, the files inside this numbered directory corresponds to the process with that particular PID.
Following are the important files located under each numbered directory (for each process):
  • cmdline – command line of the command.
  • environ – environment variables.
  • fd – Contains the file descriptors which is linked to the appropriate files.
  • limits – Contains the information about the specific limits to the process.
  • mounts – mount related information
Following are the important links under each numbered directory (for each process):
  • cwd – Link to current working directory of the process.
  • exe – Link to executable of the process.
  • root – Link to the root directory of the process.

2. /proc Files about the system information

Following are some files which are available under /proc, that contains system information such as cpuinfo, meminfo, loadavg.
  • /proc/cpuinfo – information about CPU,
  • /proc/meminfo – information about memory,
  • /proc/loadvg – load average,
  • /proc/partitions – partition related information,
  • /proc/version – linux version
Some Linux commands read the information from this /proc files and displays it. For example, free command, reads the memory information from /proc/meminfo file, formats it, and displays it.
To learn more about the individual /proc files, do “man 5 FILENAME”.
  • /proc/cmdline – Kernel command line
  • /proc/cpuinfo – Information about the processors.
  • /proc/devices – List of device drivers configured into the currently running kernel.
  • /proc/dma – Shows which DMA channels are being used at the moment.
  • /proc/fb – Frame Buffer devices.
  • /proc/filesystems – File systems supported by the kernel.
  • /proc/interrupts – Number of interrupts per IRQ on architecture.
  • /proc/iomem – This file shows the current map of the system’s memory for its various devices
  • /proc/ioports – provides a list of currently registered port regions used for input or output communication with a device
  • /proc/loadavg – Contains load average of the system
    The first three columns measure CPU utilization of the last 1, 5, and 10 minute periods.
    The fourth column shows the number of currently running processes and the total number of processes.
    The last column displays the last process ID used.
  • /proc/locks – Displays the files currently locked by the kernel
    Sample line:
    1: POSIX ADVISORY WRITE 14375 08:03:114727 0 EOF
  • /proc/meminfo – Current utilization of primary memory on the system
  • /proc/misc – This file lists miscellaneous drivers registered on the miscellaneous major device, which is number 10
  • /proc/modules – Displays a list of all modules that have been loaded by the system
  • /proc/mounts – This file provides a quick list of all mounts in use by the system
  • /proc/partitions – Very detailed information on the various partitions currently available to the system
  • /proc/pci – Full listing of every PCI device on your system
  • /proc/stat – Keeps track of a variety of different statistics about the system since it was last restarted
  • /proc/swap – Measures swap space and its utilization
  • /proc/uptime – Contains information about uptime of the system
  • /proc/version – Version of the Linux kernel, gcc, name of the Linux flavor installed.

Tuesday, July 12, 2011

/proc/sysrq-trigger the file can do things?

# Restart the computer (Reboots the kernel without first unmounting file systems or syncing disks attached to the system) 
echo "b"> / proc / sysrq-trigger
# Immediately shut down the computer (shuts off the system) 
echo "o"> / proc / sysrq-trigger
# Export the memory allocation information (you can use / var / log / message view) (Outputs memory statistics to the console) 
echo "m"> / proc / sysrq-trigger
# Export the current CPU registers and flag bits of information (Outputs all flags and registers to the console) 
echo "p"> / proc / sysrq-trigger
# Export the thread state information (Outputs a list of processes to the console) 
echo "t"> / proc / sysrq-trigger
# Deliberately crash (Crashes the system without first unmounting file systems or syncing disks attached to the system) 
echo "c"> / proc / sysrq-trigger
# Immediately re-mount all file systems (Attempts to sync disks attached to the system) 
echo "s"> / proc / sysrq-trigger
# Immediately re-mount all the file system is read-only (Attempts to unmount and remount all file systems as read-only) 
echo "u"> / proc / sysrq-trigger
Oh, in addition to two, similar to the forced cancellation feature e - Kills all processes except init using SIGTERM i - Kills all processes except init using SIGKILL

Saturday, June 18, 2011

The /proc Filesystem

Most of the /proc filesystem is read only, however there are some directories and files like /proc/sys which can be edited to modify the kernel.  Lets look into each area of the /proc filesystem.

/proc/apm -> used for checking the battery status and gaining information about a system's battery

/proc/buddyinfo -> used to diagnose fragmentation issues in memory

/proc/cmdline -> parameters that were passed to the kernel during boot

/proc/cpuinfo -> identifies the CPU and information about it on the system

/proc/crypto -> lists all installed cryptographic ciphers used by the kernel

/proc/devices -> displays information on various character and block devices

/proc/dma -> contains a list of registered ISA DMA channels

/proc/fb -> contains a list of frame buffer devices

/proc/filesystems -> shows a list of file system types that are currently supported by the kernel

/proc/interrupts -> lists the number of interrupts per IRQ

/proc/iomem -> shows a current map of the system's memory for each physical device

/proc/ioports -> contains a list of currently registered port regions

/proc/loadvg -> contains load average of the CPU and IO over time, as well as the number of running processes

/proc/mdstat -> contains information about multi-disk RAID configurations

/proc/meminfo -> contains information about memory usage on the system

/proc/modules -> contains the modules currently loaded into the kernel

/proc/mounts -> contains a list of all mounts in use by the system (similar to /etc/mtab)

/proc/partitions -> contains partition block allocation information

/proc/pci -> lists all pci devices on the system, use /sbin/lspci -vb for a more readable version

/proc/slabinfo -> detailed information about system memory

/proc/stat -> information about the system since last reboot

/proc/swaps -> shows swap space and utilization

/proc/uptime -> shows amount of time system has been up (uptime command is better)

/proc/version -> shows kernel version information as well as gcc

These are just some of the files contained in the /proc directory which provide information useful for troubleshooting and maintanence.  There are also a number of directories listed in the /proc directory which are numbered.  These numbers represent the process ID (PID) of different programs and stores the information of them within these directories.

$ ls -l | grep apache


dr-xr-xr-x 5 apache apache 0 Feb 23 09:54 4427
dr-xr-xr-x 5 apache apache 0 Feb 23 09:54 4324
dr-xr-xr-x 5 apache apache 0 Feb 23 09:54 4387
dr-xr-xr-x 5 apache apache 0 Feb 23 09:54 4426
dr-xr-xr-x 5 apache apache 0 Feb 23 09:54 4427

You can see from the example that these directories are owned by the apache process and the folders are numbered after the processes running them.  This makes it easier for troubleshooting to hunt down information about particular processes.  There are a few other directories worth noting in the /proc filesystem as well.

/proc/bus -> this directory contains information relating to the various buses available on the system
/proc/driver -> contains information relating to drivers in use by the kernel
/proc/fs -> this directory shows which file systems are exported if an NFS server is running
/proc/ide -> this directory contains information about each IDE device, each channel has a directory
/proc/irq -> each IRQ has its own directory which contains configuration for each IRQ
/proc/net -> provides details about system networking including parameters and statistics
/proc/scsi -> same as /proc/ide but for SCSI drives
/proc/sys -> this directory is unique in that it allows you to tune the kernel and its features
/proc/sys/dev -> contains parameters for particular devices
/proc/sys/fs -> contains information relating to filesystem parameters and features

The one particular directory to note here is the /proc/sys directory.  This directory contains files that can be used to tune the kernel in its running state.  You can use the echo command to insert changes into the different files and change the paremeter of the kernel, however note that a reboot to the system will restore any changes made with the echo command.  An easy way to see which files can be modifed is to use the ls -l command and look for the 'w' write access to the particular file.  There is another command sysctl which can be used in place of directing echo output to files.  The sysctl command will also change parameters in the kernel.  In order for the changes to be permanent you must edit them in the /etc/sysctl.conf file which is executed during system boot.  This would be used more after testing is done with the echo command to tune the kernel the way you want.  You shouldn't try to memorize all the locations and files in the /proc directory.  An administrator should have an understanding of where the files are and an idea of what they do in order to troubleshoot or tune their system.  There are also other utilities including lspci, top, free, apm, lsusb, and other which can produce the same output of many of the /proc files.

Saturday, August 14, 2010

Proc File System - /proc files and its informations

/proc file system contains the informations about,


  • Kernel
  • Hardware
  • Running Process


All the files under /proc can be viewed by the cat command.
/proc/ file contains the information about the running process which holds that Process ID –


These informations used by  the commands like ps and top to display the running process




For example, If you run the httpd service and it has 3992 process ID, Its information will be located in  /proc/<3992>


Some Important files under /Proc:








/proc/cpuinfo - contains the information about CPU.

/prc/mdstat - contains the information about RAID about md devices (used by  mdadm command) 



/proc/meminfo and /proc/swaps – Contain the information about memory usage and swap  usage (used by free and vmstat commands)


/proc/modules - Contains the list of modules. It can be viewed by the lsmod command.


/proc/mounts contain the mounted file system information 


/proc/partitions - Contains the partitions information 


/proc/net - contains the information about networking (Used by ifconfig and netstat ) 


/proc/version - Contains Linux kernel version (uname –v)


/proc/sys/kernel/hostname - contains system hostname


/proc/sys/net/ipv4/ip_forward -  You can make IP forwarding ON or OFF by editing this file. the same can be done with sysctl -w as well