Science and technology

Troubleshoot utilizing the proc filesystem on Linux

The proc filesystem is a crucial function of Linux that you may’t ignore. proc is a pseudo or digital filesystem that gives an interface to kernel information buildings. In different phrases, proc is not an precise filesystem within the real-world sense; moderately, it resides solely in reminiscence and never on a disk. It is mechanically mounted by the system.

Most of its contents are common information and directories, so you need to use most common Linux instruments to navigate the proc filesystem. The examples on this article ought to run the identical on any Linux distribution. My system makes use of:

$ cat /and many others/redhat-release
Red Hat Enterprise Linux Server launch 7.eight (Maipo)
$
 
$ uname  -r
three.10.Zero-1127.el7.x86_64
$

Basic proc utilization

To discover out the place the /proc filesystem resides, run the mount command and seek for proc. Here, you may see that proc is mounted on the /proc listing:

$ mount | grep proc
proc on /proc sort proc (rw,nosuid,nodev,noexec,relatime)
systemd-1 on /proc/sys/fs/binfmt_misc sort autofs (rw,relatime,fd=26,pgrp=1,timeout=Zero,minproto=5,maxproto=5,direct,pipe_ino=9506)
nfsd on /proc/fs/nfsd sort nfsd (rw,relatime)
binfmt_misc on /proc/sys/fs/binfmt_misc sort binfmt_misc (rw,relatime)
$

Move into the /proc listing and discover it. You will see quite a lot of directories with numbers; the numbers are simply course of IDs (PIDs) for the processes which can be executing. The information with names are common information which can be relevant system-wide and never associated to a particular course of:

$ cd /proc/
$ pwd
/proc
$ ls
1      157    22827  33    3413  3618  384   4709  512   5571  66    741   798   88         consoles     keys          scsi
10     15868  23     3340  3414  362   385   4768  513   5581  6723  742   799   880        cpuinfo      key-users     self
101    15900  23323  3341  3415  3622  39    4769  514   56    68    7466  eight     891        crypto       kmsg          slabinfo
1033   16     23370  3342  346   363   392   4770  515   5637  69    747   80    9          gadgets      kpagecount    softirqs
104    17     23380  3343  3467  364   394   48    516   5652  7     75    800   906        diskstats    kpageflags    stat
10416  17580  23383  3344  347   365   four     4804  517   57    70    76    8367  928        dma          loadavg       swaps
105    18     23469  3346  349   37    40    4805  518   58    7071  77    839   96         driver       locks         sys
106    19     23491  3365  35    374   4094  4807  519   59    71    78    840   98         execdomains  mdstat        sysrq-trigger
107    2      23524  3366  351   375   4096  482   52    6     7199  783   842   9838       fb           meminfo       sysvipc
11     20767  23527  3392  352   376   41    483   53    601   72    784   8446  99         filesystems  misc          timer_list
11412  21     24     3397  3523  377   4180  49    5347  61    73    785   85    993        fs           modules       timer_stats
12     21014  26     3398  358   378   42    494   5348  62    735   786   86    994        interrupts   mounts        tty
120    21035  27     34    359   379   428   495   54    624   736   79    869   9970       iomem        mtrr          uptime
1263   21059  28     3408  36    38    43    508   5421  625   737   793   87    acpi       ioports      internet           model
1265   21083  29     3409  360   380   44    509   5463  63    738   794   870   buddyinfo  ipmi         pagetypeinfo  vmallocinfo
1272   22     30     3410  3602  381   45    51    5464  636   739   795   874   bus        irq          partitions    vmstat
13     22055  31     3411  3603  382   46    510   5500  64    74    796   878   cgroups    kallsyms     sched_debug   zoneinfo
14     22074  32     3412  361   383   47    511   5519  65    740   797   879   cmdline    kcore        schedstat
$

Begin by exploring some common system-wide information. For instance, /proc/cpuinfo exhibits details about the CPU on the system—particularly, its make, mannequin, variety of cores, velocity, CPU flags, and many others.:

$ cat /proc/cpuinfo

Similarly, /proc/meminfo supplies details about the first reminiscence or RAM on the system. It additionally supplies extra statistics, like how a lot reminiscence is used, free, and so forth:

$ cat /proc/meminfo

To view all of the kernel modules which can be loaded, have a look at the /proc/modules file:

$ cat /proc/modules

To see what all filesystems are supported by your system, have a look at /proc/filesystems:

$ cat /proc/filesystems

Next, have a look at the per-process information; for instance, systemd, which has a PID of 1:

$ ps aux | grep -i systemd | head -1
root         1  Zero.Zero  Zero.Zero 195976  9088 ?        Ss   Mar03   Zero:06 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
$

Move to the listing named 1 inside /proc and see what’s there. There are many information current, and their names are considerably self-explanatory:

$ cd /proc/1
$ pwd
/proc/1
$

$ ls
attr        cmdline          environ  io         mem         ns             pagemap      sched      stack    activity
autogroup   comm             exe      limits     mountinfo   numa_maps      patch_state  schedstat  stat     timers
auxv        coredump_filter  fd       loginuid   mounts      oom_adj        persona  sessionid  statm    uid_map
cgroup      cpuset           fdinfo   map_files  mountstats  oom_score      projid_map   setgroups  standing   wchan
clear_refs  cwd              gid_map  maps       internet         oom_score_adj  root         smaps      syscall
$

To discover out if these information are current for every of the processes, choose the present shell ID. You can get that data by working echo $$. $$ is a particular variable that saves the present shell’s PID. Go to /proc and cd into the listing with the identical quantity because the PID. The information are virtually similar to those for PID 1 or systemd:

$ echo $$
21059
$
$ cd /proc/21059
$ pwd
/proc/21059
$
$ ls
attr        cmdline          environ  io         mem         ns             pagemap      sched      stack    activity
autogroup   comm             exe      limits     mountinfo   numa_maps      patch_state  schedstat  stat     timers
auxv        coredump_filter  fd       loginuid   mounts      oom_adj        persona  sessionid  statm    uid_map
cgroup      cpuset           fdinfo   map_files  mountstats  oom_score      projid_map   setgroups  standing   wchan
clear_refs  cwd              gid_map  maps       internet         oom_score_adj  root         smaps      syscall
$

To see what these information include, run a long-running course of. Open a terminal and run the tty command to see which terminal you’re utilizing. Then sort the cat command and hit Enter. This command will sit and wait on your enter:


Open one other terminal and discover the PID of cat utilizing the pgrep command:


Now, discover the very first per-process file, cmdline. This file exhibits how the command line is executed, if any parameters are used, and many others.:

$ cat /proc/24335/cmdline
cat$

Next, have a look at the listing referred to as cwd, which is form of a symbolic hyperlink (symlink) to the listing the place the cat command was executed; on this case, that’s /root:

$ ls -l  /proc/24335/cwd
lrwxrwxrwx. 1 root root Zero Mar  four 03:35 /proc/24335/cwd -> /root
$

If a binary is executed and a course of is spawned, it opens up just a few information by default. In common, it opens an ordinary in (stdin), customary out (stdout), and an ordinary err (stderr). If you checklist the fd listing below /proc/ adopted by the PID, you may see it returns three symbolic hyperlinks, all pointing to the terminal (pts2) that was used to execute the command:

$ ls -l  /proc/24335/fd/
complete Zero
lrwx------. 1 root root 64 Mar  four 03:35 Zero -> /dev/pts/2
lrwx------. 1 root root 64 Mar  four 03:35 1 -> /dev/pts/2
lrwx------. 1 root root 64 Mar  four 03:35 2 -> /dev/pts/2
$

Another essential file is exe, which is a symlink pointing to absolutely the path of the binary that was executed. In this case, it’s the path of the cat command:

$ ls -l /proc/24335/exe
lrwxrwxrwx. 1 root root Zero Mar  four 03:35 /proc/24335/exe -> /usr/bin/cat
$

Similarly, when you cat the environ per-process file, you may view all of the atmosphere variables which can be outlined for the cat course of:

$ cat /proc/24335/environ

Important information in proc

The examples above present quite a lot of details about working processes and your system on the whole that may support in debugging and troubleshooting points.

Important per-process information

The following are essential per-process information to search for within the /proc/ filesystem:

  • /proc/$pid/cmdline Holds the whole command line for the method
  • /proc/$pid/cwd Symbolic hyperlink to the method’ present working listing
  • /proc/$pid/environ Contains the preliminary atmosphere that was set when this system began
  • /proc/$pid/exe Symbolic hyperlink to the trail of the file that was executed
  • /proc/$pid/fd Subdirectory for itemizing information which were opened by the method
  • /proc/$pid/io Contains I/O statistics for the method
  • /proc/$pid/limits Displays the method useful resource restrict
  • /proc/$pid/maps Currently mapped reminiscence areas and entry permissions
  • /proc/$pid/stack Trace of perform calls within the course of’ kernel stack
  • /proc/$pid/stat Status details about the method
  • /proc/$pid/activity/ Directory that accommodates thread data

Important system-wide information

Here is a listing of essential common information (i.e., not particular to any course of):

  • /proc/cmdline Arguments handed to the Linux kernel throughout boot time
  • /proc/cpuinfo CPU-related data
  • /proc/meminfo Memory utilization statistics
  • /proc/filesystems Listing of filesystems supported by the kernel
  • /proc/modules Kernel modules which can be presently loaded
  • /proc/partitions Information about every partition on the system
  • /proc/swaps Information about swap area on the system
  • /proc/self Directory refers back to the course of accessing the /proc filesystem
  • /proc/slabinfo Information about kernel caches
  • /proc/sys Various information and sub-directories about kernel variables

Further steps

This overview of the proc filesystem solely touches on the potentialities it presents. For extra data, test proc‘s man web page by getting into the man proc command or accessing the web model of the proc man page.

Most Popular

breakingExpress.com features the latest multimedia technologies, from live video streaming to audio packages to searchable archives of news features and background information. The site is updated continuously throughout the day.

Copyright © 2017 Breaking Express, Green Media Corporation

To Top