{"id":12707,"date":"2019-03-28T14:06:36","date_gmt":"2019-03-28T14:06:36","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=12707"},"modified":"2019-03-28T14:06:36","modified_gmt":"2019-03-28T14:06:36","slug":"exploring-proc-file-system-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/28\/exploring-proc-file-system-in-linux\/","title":{"rendered":"Exploring \/proc File System in Linux"},"content":{"rendered":"<p>Today, we are going to take a look inside the\u00a0<strong>\/proc<\/strong>\u00a0directory and develop a familiarity with it. The\u00a0<strong>\/proc<\/strong>\u00a0directory is present on all\u00a0<strong>Linux<\/strong>\u00a0systems, regardless of flavor or architecture.<\/p>\n<p>One misconception that we have to immediately clear up is that the\u00a0<strong>\/proc<\/strong>\u00a0directory is\u00a0<strong>NOT<\/strong>\u00a0a real\u00a0<strong>File System<\/strong>, in the sense of the term. It is a\u00a0<strong>Virtual File System<\/strong>. Contained within the\u00a0<strong>procfs<\/strong>\u00a0are information about processes and other system information. It is mapped to\u00a0<strong>\/proc<\/strong>\u00a0and mounted at\u00a0<strong>boot<\/strong>\u00a0time.<\/p>\n<div id=\"attachment_4564\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/10\/proc-file-system.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4564\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/10\/proc-file-system.png\" alt=\"Linux proc file system\" width=\"435\" height=\"321\" aria-describedby=\"caption-attachment-4564\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-4564\" class=\"wp-caption-text\">Exploring \/proc File System<\/p>\n<\/div>\n<p>First, lets get into the\u00a0<strong>\/proc<\/strong>\u00a0directory and have a look around:<\/p>\n<pre># cd \/proc<\/pre>\n<p>The first thing that you will notice is that there are some\u00a0<strong>familiar sounding files<\/strong>, and then a whole bunch of\u00a0<strong>numbered directories<\/strong>. The\u00a0<strong>numbered directories<\/strong>\u00a0represent\u00a0<strong>processes<\/strong>, better known as\u00a0<strong>PIDs<\/strong>, and within them, a command that occupies them. The files contain system information such as\u00a0<strong>memor<\/strong>y (<strong>meminfo<\/strong>),\u00a0<strong>CPU information<\/strong>\u00a0(<strong>cpuinfo<\/strong>), and available\u00a0<strong>filesystems<\/strong>.<\/p>\n<p><strong>Read Also:\u00a0<\/strong>\u00a0<a href=\"https:\/\/www.tecmint.com\/10-examples-of-linux-free-command\/\" target=\"_blank\" rel=\"noopener\">Linux Free Command to Check Physical Memory and Swap Memory<\/a><\/p>\n<p>Let\u2019s take a look at one of the files first:<\/p>\n<pre># cat \/proc\/meminfo<\/pre>\n<h5>Sample Output<\/h5>\n<p>which returns something similar to this:<\/p>\n<pre>MemTotal:         604340 kB\r\nMemFree:           54240 kB\r\nBuffers:           18700 kB\r\nCached:           369020 kB\r\nSwapCached:            0 kB\r\nActive:           312556 kB\r\nInactive:         164856 kB\r\nActive(anon):      89744 kB\r\nInactive(anon):      360 kB\r\nActive(file):     222812 kB\r\nInactive(file):   164496 kB\r\nUnevictable:           0 kB\r\nMlocked:               0 kB\r\nSwapTotal:             0 kB\r\nSwapFree:              0 kB\r\nDirty:                 0 kB\r\nWriteback:             0 kB\r\nAnonPages:         89724 kB\r\nMapped:            18012 kB\r\nShmem:               412 kB\r\nSlab:              50104 kB\r\nSReclaimable:      40224 kB\r\n...<\/pre>\n<p>As you can see,\u00a0<strong>\/proc\/meminfo<\/strong>\u00a0contains a bunch of information about your system\u2019s memory, including the total amount available (in\u00a0<strong>kb<\/strong>) and the amount free on the top two lines.<\/p>\n<p>Running the\u00a0<a href=\"https:\/\/www.tecmint.com\/13-basic-cat-command-examples-in-linux\/\" target=\"_blank\" rel=\"noopener\">cat command<\/a>\u00a0on any of the files in\u00a0<strong>\/proc<\/strong>\u00a0will output their contents. Information about any files is available in the man page by running:<\/p>\n<pre># man 5 \/proc\/&lt;filename&gt;<\/pre>\n<p>I will give you quick rundown on\u00a0<strong>\/proc\u2019s<\/strong>\u00a0files:<\/p>\n<ol>\n<li><strong>\/proc\/cmdline<\/strong>\u00a0\u2013 Kernel command line information.<\/li>\n<li><strong>\/proc\/console<\/strong>\u00a0\u2013 Information about current consoles including tty.<\/li>\n<li><strong>\/proc\/devices<\/strong>\u00a0\u2013 Device drivers currently configured for the running kernel.<\/li>\n<li><strong>\/proc\/dma<\/strong>\u00a0\u2013 Info about current DMA channels.<\/li>\n<li><strong>\/proc\/fb<\/strong>\u00a0\u2013 Framebuffer devices.<\/li>\n<li><strong>\/proc\/filesystem<\/strong>s \u2013 Current filesystems supported by the kernel.<\/li>\n<li><strong>\/proc\/iomem<\/strong>\u00a0\u2013 Current system memory map for devices.<\/li>\n<li><strong>\/proc\/ioports<\/strong>\u00a0\u2013 Registered port regions for input output communication with device.<\/li>\n<li><strong>\/proc\/loadavg<\/strong>\u00a0\u2013 System load average.<\/li>\n<li><strong>\/proc\/locks<\/strong>\u00a0\u2013 Files currently locked by kernel.<\/li>\n<li><strong>\/proc\/meminfo<\/strong>\u00a0\u2013 Info about system memory (see above example).<\/li>\n<li><strong>\/proc\/misc<\/strong>\u00a0\u2013 Miscellaneous drivers registered for miscellaneous major device.<\/li>\n<li><strong>\/proc\/modules<\/strong>\u00a0\u2013 Currently loaded kernel modules.<\/li>\n<li><strong>\/proc\/mounts<\/strong>\u00a0\u2013 List of all mounts in use by system.<\/li>\n<li><strong>\/proc\/partitions<\/strong>\u00a0\u2013 Detailed info about partitions available to the system.<\/li>\n<li><strong>\/proc\/pci<\/strong>\u00a0\u2013 Information about every PCI device.<\/li>\n<li><strong>\/proc\/stat<\/strong>\u00a0\u2013 Record or various statistics kept from last reboot.<\/li>\n<li><strong>\/proc\/swap<\/strong>\u00a0\u2013 Information about swap space.<\/li>\n<li><strong>\/proc\/uptime<\/strong>\u00a0\u2013 Uptime information (in seconds).<\/li>\n<li><strong>\/proc\/version<\/strong>\u00a0\u2013 Kernel version, gcc version, and Linux distribution installed.<\/li>\n<\/ol>\n<p>Within\u00a0<strong>\/proc\u2019s<\/strong>\u00a0numbered directories you will find a few\u00a0<strong>files<\/strong>\u00a0and\u00a0<strong>links<\/strong>. Remember that these directories\u2019 numbers correlate to the\u00a0<strong>PID<\/strong>\u00a0of the command being run within them. Let\u2019s use an example. On my system, there is a folder name\u00a0<strong>\/proc\/12<\/strong>:<\/p>\n<pre># cd \/proc\/12\r\n# ls<\/pre>\n<h5>Sample Output<\/h5>\n<pre>attr        coredump_filter  io         mounts      oom_score_adj  smaps    wchan\r\nautogroup   cpuset           latency    mountstats  pagemap        stack\r\nauxv        cwd              limits     net         personality    stat\r\ncgroup      environ          loginuid   ns          root           statm\r\nclear_refs  exe              maps       numa_maps   sched          status\r\ncmdline     fd               mem        oom_adj     schedstat      syscall\r\ncomm        fdinfo           mountinfo  oom_score   sessionid      task<\/pre>\n<p>If I run:<\/p>\n<pre># cat \/proc\/12\/status<\/pre>\n<p>I get the following:<\/p>\n<pre>Name:\txenwatch\r\nState:\tS (sleeping)\r\nTgid:\t12\r\nPid:\t12\r\nPPid:\t2\r\nTracerPid:\t0\r\nUid:\t0\t0\t0\t0\r\nGid:\t0\t0\t0\t0\r\nFDSize:\t64\r\nGroups:\r\nThreads:\t1\r\nSigQ:\t1\/4592\r\nSigPnd:\t0000000000000000\r\nShdPnd:\t0000000000000000\r\nSigBlk:\t0000000000000000\r\nSigIgn:\tffffffffffffffff\r\nSigCgt:\t0000000000000000\r\nCapInh:\t0000000000000000\r\nCapPrm:\tffffffffffffffff\r\nCapEff:\tffffffffffffffff\r\nCapBnd:\tffffffffffffffff\r\nCpus_allowed:\t1\r\nCpus_allowed_list:\t0\r\nMems_allowed:\t00000000,00000001\r\nMems_allowed_list:\t0\r\nvoluntary_ctxt_switches:\t84\r\nnonvoluntary_ctxt_switches:\t0<\/pre>\n<p>So, what does this mean? Well, the important part is at the top. We can see from the status file that this process belongs to\u00a0<strong>xenwatch<\/strong>. Its current state is\u00a0<strong>sleeping<\/strong>, and its process<strong>\u00a0ID<\/strong>\u00a0is\u00a0<strong>12<\/strong>, obviously. We also can see who is running this, as\u00a0<strong>UID<\/strong>\u00a0and\u00a0<strong>GID<\/strong>\u00a0are\u00a0<strong>0<\/strong>, indicating that this process belongs to the\u00a0<strong>root<\/strong>\u00a0user.<\/p>\n<p>In any numbered directory, you will have a similar file structure. The most important ones, and their descriptions, are as follows:<\/p>\n<ol>\n<li><strong>cmdline<\/strong>\u00a0\u2013 command line of the process<\/li>\n<li><strong>environ<\/strong>\u00a0\u2013 environmental variables<\/li>\n<li><strong>fd<\/strong>\u00a0\u2013 file descriptors<\/li>\n<li><strong>limits<\/strong>\u00a0\u2013 contains information about the limits of the process<\/li>\n<li><strong>mounts<\/strong>\u00a0\u2013 related information<\/li>\n<\/ol>\n<p>You will also notice a number of links in the numbered directory:<\/p>\n<ol>\n<li><strong>cwd<\/strong>\u00a0\u2013 a link to the current working directory of the process<\/li>\n<li><strong>exe<\/strong>\u00a0\u2013 link to the executable of the process<\/li>\n<li><strong>root<\/strong>\u00a0\u2013 link to the work directory of the process<\/li>\n<\/ol>\n<p>This should get you started with familiarizing yourself with the\u00a0<strong>\/proc<\/strong>\u00a0directory. It should also provide insight to how a number of commands obtain their info, such as\u00a0<strong>uptime<\/strong>,\u00a0<strong>lsof<\/strong>,\u00a0<strong>mount<\/strong>, and\u00a0<strong>ps<\/strong>, just to name a few.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/exploring-proc-file-system-in-linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today, we are going to take a look inside the\u00a0\/proc\u00a0directory and develop a familiarity with it. The\u00a0\/proc\u00a0directory is present on all\u00a0Linux\u00a0systems, regardless of flavor or architecture. One misconception that we have to immediately clear up is that the\u00a0\/proc\u00a0directory is\u00a0NOT\u00a0a real\u00a0File System, in the sense of the term. It is a\u00a0Virtual File System. Contained within the\u00a0procfs\u00a0are &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/28\/exploring-proc-file-system-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Exploring \/proc File System in Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-12707","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12707","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=12707"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12707\/revisions"}],"predecessor-version":[{"id":12708,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12707\/revisions\/12708"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=12707"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=12707"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=12707"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}