Linux menu

Showing posts with label Linux Performance Tuning & Monitoring. Show all posts
Showing posts with label Linux Performance Tuning & Monitoring. Show all posts

Monday, October 27, 2014

Performance tuning Linux Kernel with swappiness parameter

The swappiness parameter controls the tendency of the kernel to move processes out of physical memory and onto the swap disk. Because disks are much slower than RAM, this can lead to slower response times for system and applications if processes are too aggressively moved out of memory.

swappiness can have a value of between 0 and 100

swappiness=0 tells the kernel to avoid swapping processes out of physical memory for as long as possible
swappiness=100 tells the kernel to aggressively swap processes out of physical memory and move them to swap cache

The default setting in Linux is swappiness=60. Reducing the default value of swappiness will probably improve overall performance for a typical desktop installation. A value of swappiness=10 is recommended, but feel free to experiment.

To check the swappiness value use command: cat /proc/sys/vm/swappiness

To make a change permanent, edit the configuration file with your favorite editor:

vi /etc/sysctl.conf
and add following parameter to the end of the file like so:
vm.swappiness=10
Save the file and reboot.

Still, there are users who insist that, for example, a system backup should never force OpenOffice out to disk. They don't care how quickly a system maintenance application runs at 3:00 in the morning, but they care a lot about how the system responds when they are at the keyboard. This wish was expressed repeatedly until Andrew Morton exclaimed:

 "I set swappiness to zero and it didn't do what I wanted it to do.


Oracle DataBase tuning on Linux

Verify that the kernel parameters shown in the following table are set to values greater than or equal to the minimum value shown. If the current value for any parameter is higher than the value listed in this table, then do not change the value of that parameter. The procedure following the table describes how to verify and set the values.
Execute command
/sbin/sysctl -a | egrep "kernel.shmall|kernel.shmmax|kernel.shmmn|kernel.sem"
and compare the values with the values in the table below
Note:
The kernel parameter and shell limit values shown in the following section are minimum values only. For production database systems, Oracle recommends that you tune these values to optimize the performance of the system. Refer to the operating system documentation for more information about tuning kernel parameters.
Parameter
Minimum Value
Recommended value
File
semmsl
semmns
semopm
semmni
250
32000
100
128
Set only if those that are set by OS or other applications are lower/proc/sys/kernel/sem
shmall2097152shmmax/page_size
usually page_size=4
/proc/sys/kernel/shmall
shmmaxMinimum of the following values:
·       Half the size of the memory
·       4GB - 1 byte
Note: The minimum value required for shmmax is 0.5 GB. However, Oracle recommends that you set the value of shmmax to 2.0 GB for optimum performance of the system.
Half of RAM or if swap file is less then half of RAM the size of swap file/proc/sys/kernel/shmmax
shmmni4096/proc/sys/kernel/shmmni
file-max512 * PROCESSES/proc/sys/fs/file-max
ip_local_port_rangeMinimum:9000
Maximum: 65000
/proc/sys/net/ipv4/ip_local_port_range
rmem_default262144/proc/sys/net/core/rmem_default
rmem_max4194304/proc/sys/net/core/rmem_max
wmem_default262144/proc/sys/net/core/wmem_default
wmem_max1048576/proc/sys/net/core/wmem_max
tcp_wmem262144/proc/sys/net/ipv4/tcp_wmem
tcp_rmem4194304/proc/sys/net/ipv4/tcp_rmem
To display the current value specified for these kernel parameters, and to change them if necessary, use the following steps:
Enter the commands shown in the following table to display the current values of the kernel parameters, make a note of these values and identify any values that you must change:
For semmsl, semmns, semopm, and semmni
# /sbin/sysctl -a | grep sem 
This command displays the value of the semaphore parameters in the order listed.
shmall, shmmax, and shmmni
# /sbin/sysctl -a | grep shm 
This command displays the details of the shared memory segment sizes.file-max
# /sbin/sysctl -a | grep file-max  
This command displays the maximum number of file handles.
ip_local_port_range
# /sbin/sysctl -a | grep ip_local_port_range
This command displays a range of port numbers.
rmem_default
# /sbin/sysctl -a | grep rmem_default
rmem_max
# /sbin/sysctl -a | grep rmem_max
wmem_default
# /sbin/sysctl -a | grep wmem_default
wmem_max
# /sbin/sysctl -a | grep wmem_max
tcp_wmem
# /sbin/sysctl -a | grep tcp_wmem
tcp_rmem
# /sbin/sysctl -a | grep tcp_rmem
If the value of any kernel parameter is different from the minimum value, then complete the following procedure:
Using any text editor, create or edit the /etc/sysctl.conf file, and add or edit lines similar to the following:
Note:
Include lines only for the kernel parameter values that you want to change. For the semaphore parameters (kernel.sem), you must specify all four values. However, if any of the current values are larger than the minimum value, then specify the larger value.
fs.file-max = 512 * PROCESSES
kernel.shmall = 2097152
kernel.shmmax = 2147483648
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
or
kernel.sem = 250 256000 100 1024
net.ipv4.ip_local_port_range = 1024 65000
net.core.rmem_default = 4194304
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 262144
net.ipv4.tcp_wmem = 262144 262144 262144
net.ipv4.tcp_rmem = 4194304 4194304 4194304
Note:
The minimum value required for shmmax is 0.5 GB. However, Oracle recommends that you set the value of shmmax to 2.0 GB for optimum performance of the system.
By specifying the values in the /etc/sysctl.conf file, they persist when you restart the system. However, on SUSE Linux Enterprise Server systems, enter the following command to ensure that the system reads the /etc/sysctl.conf file when it restarts:
# /sbin/chkconfig boot.sysctl on
Enter the following command to change the current values of the kernel parameters:
# /sbin/sysctl -p
Review the output from this command to verify that the values are correct. If the values are incorrect, edit the /etc/sysctl.conf file, then enter this command again.
Enter the command /sbin/sysctl -a to confirm that the values are set correctly.
On SUSE systems only, enter the following command to cause the system to read the /etc/sysctl.conf file when it restarts:
# /sbin/chkconfig boot.sysctl on
On SUSE systems only, you must enter the GID of the oinstall group as the value for the parameter /proc/sys/vm/hugetlb_shm_group. Doing this grants members of oinstall a group permission to create shared memory segments.
For example, where the oinstall group GID is 501:
# echo 501 > /proc/sys/vm/hugetlb_shm_group
After running this command, use vi to add the following text to /etc/sysctl.conf, and enable the boot.sysctl script to run on system restart:
vm.hugetlb_shm_group=501
Note:
Only one group can be defined as the vm.hugetlb_shm_group.
After updating the values of kernel parameters in the /etc/sysctl.conf file, either restart the computer, or run the command sysctl -p to make the changes in the /etc/sysctl.conf file available in the active kernel memory.
  • Set Shell Limits for the oracle User
    To improve the performance of the software, you must increase the following shell limits for the oracle user:

    Shell Limit
    Item in limits.conf
    Hard Limit
    Maximum number of open file descriptorsnofile65536
    Maximum number of processes available to a single usernproc16384
    To increase the shell limits:
    Add the following lines to the /etc/security/limits.conf file:
    oracle              soft    nproc   2047
    oracle              hard    nproc   16384
    oracle              soft    nofile  1024
    oracle              hard    nofile  65536
    Add or edit the following line in the /etc/pam.d/login file, if it does not already exist:
    session    required     pam_limits.so
    Depending on the oracle user's default shell, make the following changes to the default shell start-up file:
    ·       For the Bourne, Bash, or Korn shell, add the following lines to the /etc/profile file (or the file on SUSE Linux Enterprise Server systems /etc/profile.local):
    if [ $USER = "oracle" ]; then
            if [ $SHELL = "/bin/ksh" ]; then
                  ulimit -p 16384
                  ulimit -n 65536
            else
                  ulimit -u 16384 -n 65536
            fi
    fi

  • PROC file System in Linux explained

    Each and every Linux user uses the below commands in their day to day system administration activities.
    • Ps
    • Uptime
    • Free
    • uname etc.

    The above mentioned are few in the long list. The amount of information those commands provide to a user is just outstanding, and is always accurate. But where does these information come from. Another most amazing fact about those commands are that they provide a real time data. Which means each time you run the command, the output will be slightly different.

    This means its fetching information from a place which is very dynamic in nature and also is fetching from a source which is very much credible and provides a real and updated data each time.

    When you talk about computers, its an obvious fact that you will talk about operating system's. And when you talk about operating system you are talking about the kernel. Linus Torvalds, once quoted in one of the documentary films about Linux, that...

    To kind of explain what Linux is, you have to explain what an operating system is, and the thing about operating system is that you are never ever supposed to see it, because nobody really uses an operating system. People use programs on their computer.And the only mission in life, of an operating system is to help those programs run. So an operating system never does anything on its own. Its only waiting for the programs to ask for certain resources or ask for a certain file on the disk, or ask for the programs to connect to outside world, then the operating system kicks in and tries to make it easy for people to write programs.


    -Linux Torvalds
    Creator, Linux Kernel


    The explanation given by Linux Torvalds is quite simple and to the point (Who can explain what Linux is, better than him smiley). As kernel is the one who maintains the system for making resources available to different programs, only kernel knows the current resource utilization, and other current status about the system.

    So when a programs like ps or top needs details about the current running status, it should ask the kernel, because its the perfect source for accurate and precise result.

    For making things easier proc file system was made. Its a mechanism provided to access the underlying kernel data structures. It also helps to modify some of the kernel parameters, at run time.

    /proc file system is a mechanism provided, so that kernel can send information to processes. This is an interface provided to the user, to interact with the kernel and get the required information about processes running on the system. Please don't forget the fact that, the /proc file system also allows you to change some parameters on the fly (on current running system with immediate effect.)


    The /proc file system is nicely documented in the proc man page. You can access this document by running the below command on a linux system.

    ?
    1
    #man proc

    The first line, you will encounter inside that man page is...

    proc - process information pseudo-file system


    The man page describes it further as The proc file system is a pseudo-file system which is used as an inter‐face to kernel data structures.  It is commonly mounted at /proc.  Most of  it  is  read-only,  but  some  files  allow  kernel variables to be changed.

    Now that we have a little bit of idea about what /proc file system is, let's have a look at some of the interesting facts about it.

    • PROC file system is completely managed by the kernel, and is not stored on disk like other file system.
    • Its stored in RAM (memory)
    • Most of the files in /proc is of 0 bytes in size. (this is quite interesting)


    The most interesting part is that, almost all files inside /proc file system is of 0 byte in size. The thing that confuses many users is the fact that, although they are in 0 size, they still contain data when viewed. How is this possible?

    Linux is capable of handling many different types of file system's because of something called as VFS (Virtual File System). Its something like a single interface to get in touch with for reading and writing to different types of file system. I have described a little bit of VFS in my article about NFS. You can read that by accessing the below link.



    VFS makes one simple interface for Linux Kernel to access different file system's under it.


    /proc file system is also accessed by the kernel using VFS. Due to this when a user tries to access a file inside the /proc file system, proc file system creates the content of that file with the help of information in the kernel. This is the reason when you list the directory /proc, most of it is shown with 0 bytes in size, but is populated dynamically when you access it.

    Let's check this practically and understand it. There is a command in linux called file"File" command in linux is used to determine the type of the file by checking the contents of the file. It will give you "file is empty" output if the file is empty. Let's try checking the file type of any /proc file using the file command.

    Let's check this by viewing the type of the /proc/meminfo, this file is used to fetch the current memory information from the kernel.

    ?
    1
    2
    root@workstation:~# file /proc/meminfo
    /proc/meminfo: empty


    Saw that?, the output says that the file is empty. But let's try to access the file with any editor like vi, cat or less.

    ?
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    root@workstation:~# cat /proc/meminfo
    MemTotal:         502712 kB
    MemFree:           47672 kB
    Buffers:           16136 kB
    Cached:           110768 kB
    SwapCached:            0 kB
    Active:           357388 kB
    Inactive:          48264 kB
    Active(anon):     278804 kB
    Inactive(anon):      332 kB

    Note: I have not shown full output, as its quite long

    So when you access the content, the current values are populated from the kernel. This is the reason, why you get the most current and accurate status of the system from files inside /proc.

    We saw earlier that the proc man page defines proc as "process information pseudo-file system".This is because it contains details about all the current running processes. Let's see the directory listing of /proc


    ?
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    root@workstation:/proc# ll
    total 4
    dr-xr-xr-x 110 root       root                     0 Dec  8 17:06 ./
    drwxr-xr-x  23 root       root                  4096 Nov 19 04:55 ../
    dr-xr-xr-x   9 root       root                     0 Dec  8 17:06 1/
    dr-xr-xr-x   9 root       root                     0 Dec  8 17:06 10/
    dr-xr-xr-x   9 whoopsie   whoopsie                 0 Dec  8 17:06 1020/
    dr-xr-xr-x   9 root       root                     0 Dec  8 17:06 11/
    dr-xr-xr-x   9 root       root                     0 Dec  8 17:06 1122/
    dr-xr-xr-x   9 root       root                     0 Dec  8 17:06 1123/
    dr-xr-xr-x   9 root       root                     0 Dec  8 17:06 1127/
    dr-xr-xr-x   9 root       root                     0 Dec  8 17:06 1128/
    dr-xr-xr-x   9 root       root                     0 Dec  8 17:06 1129/
    dr-xr-xr-x   9 root       root                     0 Dec  8 17:06 1153/
    dr-xr-xr-x   9 root       root                     0 Dec  8 17:06 12/
    dr-xr-xr-x   9 root       root                     0 Dec  8 17:06 1233/
    dr-xr-xr-x   9 root       root                     0 Dec  8 17:06 1290/
    dr-xr-xr-x   9 root       root                     0 Dec  8 17:06 13/
    dr-xr-xr-x   9 root       ubuntu                   0 Dec  8 17:07 1393/

    You can see in the above shown directory listing that there are a lot of numbered directories inside. These directories are numbered with the corresponding PID. For example, if the Apache process is running with a PID number of 2334, then you will have a folder /proc/2334.

    The most interesting thing about these directories is that they appear and disappear, dynamically when the process starts and stops. Each and every directories named after their respective PID's contain detailed information of the current status of the process.

    Let's see what are the contents of a PID directory in /proc. Below shown is the content of a PID (an nginx worker process) directory.

    ?
    1
    2
    3
    4
    root@workstation:/proc/27140# ls
    attr       cgroup      comm             cwd      fd      latency   map_files  mountinfo   net        oom_adj        pagemap      sched      smaps  statm    task
    autogroup  clear_refs  coredump_filter  environ  fdinfo  limits    maps       mounts      ns         oom_score      personality  schedstat  stack  status   wchan
    auxv       cmdline     cpuset           exe      io      loginuid  mem        mountstats  numa_maps  oom_score_adj  root         sessionid  stat   syscall


    Let's now discuss what some of the important files inside that PID directory is meant for. Discussing all of them is beyond the scope of this article, also i myself need to understand them first to write about them :)

    • /proc/<pid>/exe file inside the PID directory points to the original exe that is being executed by the process. Its normally a symbolic link to the original location of the exe file. In our case this is /usr/sbin/nginx, as we are seeing an nginx worker process directory. This is confirmed by the below command.


    ?
    1
    2
    root@workstation:/proc/27140# ll exe
    lrwxrwxrwx 1 www-data www-data 0 Dec 10 01:17 exe -> /usr/sbin/nginx*


    • /proc/<pid>/cmdline: This contains the command that was used to start the process. This is shown when you use ps command at the last column.


    ?
    1
    2
    root@workstation:/proc/27140# cat cmdline
    nginx: master process /usr/sbin/nginx


    • /proc/<pid>/fd/: This directory contains the file descriptors opened by the process. As we are seeing the nginx process, it should have its log files, socket files (basically connections) etc. Let's see the contents of the fd directory.

    ?
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    root@workstation:/proc/27140/fd# ll
    lrwx------ 1 root root 64 Dec 10 01:18 10 -> socket:[41479]
    lrwx------ 1 root root 64 Dec 10 01:18 11 -> socket:[41480]
    lrwx------ 1 root root 64 Dec 10 01:18 12 -> socket:[41481]
    lrwx------ 1 root root 64 Dec 10 01:18 13 -> socket:[41482]
    lrwx------ 1 root root 64 Dec 10 01:18 14 -> socket:[41483]
    l-wx------ 1 root root 64 Dec 10 01:18 2 -> /var/log/nginx/error.log
    lr-x------ 1 root root 64 Dec 10 01:18 3 -> /proc/27137/auxv
    lrwx------ 1 root root 64 Dec 10 01:18 4 -> socket:[41476]
    l-wx------ 1 root root 64 Dec 10 01:18 5 -> /var/log/nginx/access.log

    • /proc/<pid>/maps: This file contains the files that are mapped to the process. Most of the times, this file contains the list of library files like .so files that are used by the process. Let's see an example, of what our nginx process is having inside the maps file.


    ?
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    root@workstation:/proc/27140# cat maps
    00400000-004ba000 r-xp 00000000 08:01 25127                              /usr/sbin/nginx
    006b9000-006ba000 r--p 000b9000 08:01 25127                              /usr/sbin/nginx
    006ba000-006ce000 rw-p 000ba000 08:01 25127                              /usr/sbin/nginx
    006ce000-006dd000 rw-p 00000000 00:00 0
    00e78000-00ed3000 rw-p 00000000 00:00 0                                  [heap]
    7f46e882b000-7f46e8837000 r-xp 00000000 08:01 21884                      /lib/x86_64-linux-gnu/libnss_files-2.15.so
    7f46e8837000-7f46e8a36000 ---p 0000c000 08:01 21884                      /lib/x86_64-linux-gnu/libnss_files-2.15.so
    7f46e8a36000-7f46e8a37000 r--p 0000b000 08:01 21884                      /lib/x86_64-linux-gnu/libnss_files-2.15.so
    7f46e8a37000-7f46e8a38000 rw-p 0000c000 08:01 21884                      /lib/x86_64-linux-gnu/libnss_files-2.15.so

    • /proc/<pid>/status: This file consists of processor and memory usage details. This file also contains the pid details as well as state of the process like sleeping or running. It also has information about the parent process, group id, user id, etc.

    ?
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    root@workstation:/proc/27140# cat status
    Name:   nginx
    State:  S (sleeping)
    Tgid:   27138
    Pid:    27138
    PPid:   1
    TracerPid:      0
    Uid:    0       0       0       0
    Gid:    0       0       0       0
    FDSize: 64
    Groups: 0
    VmPeak:    76848 kB

    Note: I have not shown the full output of most of the commands shown above.

    Let's now see some other important files inside /proc other than the proc PID directory contents. The files which we will now discuss will provide you with a detailed information about the current status of the system.  Most of the commands that reports the process status, uptime load average etc fetches information by accessing files inside /proc. How will you confirm this?

    You can confirm this by running a debugging command available in Linux, which is normally used for program debugging. The command is called strace. Strace will show you the list of files that a program is accessing. The output is quite untidy as it shows you a lot of details. Try running the below command and you will come to know that commands like uname, uptime, ps and top uses files inside /proc to fetch details.


    ?
    1
    #strace ps

    Also commands like uptime shows you the current load average. This detail is fetched from the below file.

    ?
    1
    2
    root@workstation# cat /proc/loadavg
    0.00 0.01 0.05 1/115 27562

    • /proc/meminfo : This file contains the current memory details of the running system. It will show you the full details about the memory usage. Like how much is being used for caching and how much is real use. Full memory and currently available memory etc. This is place from where the command free shows you memory details.

    ?
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    root@workstation:/proc# cat meminfo
    MemTotal:         502712 kB
    MemFree:          197672 kB
    Buffers:           10796 kB
    Cached:           141996 kB
    SwapCached:            0 kB
    Active:           168432 kB
    Inactive:          75304 kB
    Active(anon):      90988 kB
    Inactive(anon):      280 kB
    Active(file):      77444 kB
    Inactive(file):    75024 kB
    Unevictable:           0 kB


    • /proc/version: This file contains the linux and distribution version details.

    ?
    1
    2
    root@workstation:/proc# cat /proc/version
    Linux version 3.8.0-29-generic (buildd@panlong) (gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) ) #42~precise1-Ubuntu SMP Wed Aug 14 16:19:23 UTC 2013


    • /proc/diskstatsThis file contains the details of disk devices. The details include reads, writes, reads completed, writes completed, time spent on reading, sectors written etc. This is the file from where commands like iostats, fetches its information. Access the below link to know about the 14 different fields in the file.

    ?
    1
    2
    3
    root@workstation:/proc# cat diskstats
       8       0 sda 48088 175 2460234 433304 43196 36838 2571832 1694864 0 497496 2127260
       8       1 sda1 47924 175 2458922 432540 36743 36838 2571832 1688772 0 491412 2120404



    •  /proc/modules: This file contains the list of currently loaded kernel modules on your system. If you run a strace command for lsmod (which lists the current list of modules in the kernel), you will see that its accessing the /proc/modules file to fetch the details.

    • /proc/cpuinfo: Consist of complete details related to the processor. This file will show you the processor flags, processor speed, processor model name etc.

    • /proc/filesystems: This file shows you the total number of file systems that are supported by the kernel currently. This list itself contains proc file system as one of the file system supported by the kernel. But it comes under those special file system with nodevice.


    I would recommend to explore more files in the /proc directory as explaining all of them is beyond my reach and scope of this article. If you get any interesting information, please don't forget to share with us through comments.

    Now as discussed earlier, there are files inside /proc which can be modified (or files with write permissions.). This is a mechanism provided by the Linux kernel to users, so that they can modify the system behavior and kernel parameters at run time.


    Extreme care must be taken while modifying files in /proc directory. Do this only if you know what you are doing, otherwise the system can become unstable. Most of the files accept boolean values or either predefined values. So don't edit or send values that are unacceptable.


    The directory /proc/sys contains the files which are writable at run time. This can be done by redirecting required values to that file. Let's see some of the files inside /proc/sys/kernel. This directory contains hostname, domain name etc.

    • /proc/sys/kernel/hostname: Host name of the system
    • /proc/sys/kernel/domainname: Domain to which the host belongs to

    When you fire the hostname command, what it does is to write the hostname inside the file/proc/sys/kernel/hostname file. Please remember the fact that this way of setting up the hostname will not make it permanent.

    Anything you modify on the fly, by editing /proc/sys/ files, is all temporary. Which means the data will be flushed on shutdown. Hence to make it permanent, you either need to modify the sysctl parameters or other relevant recommended locations. For example edit /etc/sysconfig/network file for making your hostname permanent.

    Another directory which is writable is /proc/sys/net/ipv4/. This directory contains all those files which can be used to modify the networking behavior of your Linux system.  Most of the system admin's, must be familiar with this directory, as this directory contains ip_forward file, which is modified to enable ip forwarding (to make Linux act as a router.)



    Some interesting files inside this directory are mentioned below.

    • /proc/sys/net/ipv4/ip_forward: This accepts two values, either 1 or 0. 1 means ip forwarding is enabled, and 0 means its disabled. To enable ip forward on the fly, you can run the below command.

    ?
    1
    echo 1 > /proc/sys/net/ipv4/ip_forward

    • /proc/sys/net/ipv4/ipfrag_high_thresh: Highest memory allowed to be used to reassemble ip fragments. If the data is too large while sending its breaked down to different fragments and sent. when this limit is reached the sending machine has to resend those fragments. Its measured in bytes.
    • /proc/sys/net/ipv4/icmp_echo_ignore_all: This will ignore all ping requests to the host. This also has either a 0 or 1 value. 0 for disabled and 1 for enabled.
    • /proc/sys/net/ipv4/icmp_echo_ignore_broadcastsThis will ignore icmp broadcast requests.
    • /proc/sys/net/ipv4/ip_default_ttl:  This file can be modified to change the default TTL value. TTL is time to live, in number of hops that comes in between the source and destination.

    If you are interested to understand how TTL works, i would recommend reading my article on traceroute and its working.


    Some other interesting files inside /proc/sys/net/ipv4/, are mentioned below.

    • tcp_rmem
    • tcp_window_scaling
    • tcp_wmem

    They are used to tune TCP performance in Linux. I would recommend you to read the below article to understand their use.


    As i told before, its quite difficult to explain all the files in /proc. So explore more files inside this directory to understand its use. Also please dont forget to share it with me through comments if you find anything interesting (this will help me as well as our readers to gain more information about them).

    Another interesting directory inside /proc  is the self directory (/proc/self). Its always a symbolic link to the current process. Which means if you do a ls -l on /proc/self directory, each time the symbolic link is different. The sym link points to the process directory of the process that views the /proc/self directory (in our case the ls -l process.)

    As each time you run ls -l on the /proc/self, the ls -l is a different process with different PID, hence it will show the different sym links.

    Some points to remember about /proc file system in linux


    • proc is a special file system and is not associated with any hard drive device.
    • Files inside /proc are not real files, they act as an interface to kernel data structures and process information. As they are not real files, properties like file size is not applicable to them (hence shown as zero bytes)
    • Contents inside /proc files are populated dynamically when requested. Due to this the data fetched from /proc is the most recent data provided by the kernel
    • Certian files inside /proc can be modified to change the behaviour of a running kernel. For example, /proc/sys/ files.
    • Most of the system monitoring commands like ps, top, free, etc use process files inside /proc/to fetch information.
    • Complete detail of a running process can be fetched from the /proc/<pid> directory.
    • A special directory called /proc/self can be used by a program to find details about its own process.

    As i always say, Please let me know if you find any mistake in this article through comments. Because rectifying it will be helpful to me as well as other readers.