<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0"><channel><title><![CDATA[GOPAKUMAR RAJAPPAN]]></title><description><![CDATA[First Principles: A Guiding Path to Understanding Tech Advancements]]></description><link>https://www.gopakumar-rajappan.com</link><image><url>https://substackcdn.com/image/fetch/$s_!0BMm!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd74e8425-0a13-40ad-86b5-27bdf5afe57f_800x800.png</url><title>GOPAKUMAR RAJAPPAN</title><link>https://www.gopakumar-rajappan.com</link></image><generator>Substack</generator><lastBuildDate>Mon, 18 May 2026 04:44:05 GMT</lastBuildDate><atom:link href="https://www.gopakumar-rajappan.com/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[GOPAKUMAR RAJAPPAN]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[gopakumarrajappan@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[gopakumarrajappan@substack.com]]></itunes:email><itunes:name><![CDATA[GOPAKUMAR RAJAPPAN]]></itunes:name></itunes:owner><itunes:author><![CDATA[GOPAKUMAR RAJAPPAN]]></itunes:author><googleplay:owner><![CDATA[gopakumarrajappan@substack.com]]></googleplay:owner><googleplay:email><![CDATA[gopakumarrajappan@substack.com]]></googleplay:email><googleplay:author><![CDATA[GOPAKUMAR RAJAPPAN]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[Load Average in Linux]]></title><description><![CDATA[The load average is a critical metric in Linux, offering insights into system performance and workload.]]></description><link>https://www.gopakumar-rajappan.com/p/load-average-in-linux</link><guid isPermaLink="false">https://www.gopakumar-rajappan.com/p/load-average-in-linux</guid><dc:creator><![CDATA[GOPAKUMAR RAJAPPAN]]></dc:creator><pubDate>Tue, 10 Dec 2024 01:57:35 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!hQpL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cf1e1e8-7f28-4619-8743-7b2735090533_1024x1024.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!hQpL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cf1e1e8-7f28-4619-8743-7b2735090533_1024x1024.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!hQpL!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cf1e1e8-7f28-4619-8743-7b2735090533_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!hQpL!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cf1e1e8-7f28-4619-8743-7b2735090533_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!hQpL!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cf1e1e8-7f28-4619-8743-7b2735090533_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!hQpL!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cf1e1e8-7f28-4619-8743-7b2735090533_1024x1024.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!hQpL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cf1e1e8-7f28-4619-8743-7b2735090533_1024x1024.webp" width="1024" height="1024" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8cf1e1e8-7f28-4619-8743-7b2735090533_1024x1024.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:146054,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/webp&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!hQpL!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cf1e1e8-7f28-4619-8743-7b2735090533_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!hQpL!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cf1e1e8-7f28-4619-8743-7b2735090533_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!hQpL!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cf1e1e8-7f28-4619-8743-7b2735090533_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!hQpL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cf1e1e8-7f28-4619-8743-7b2735090533_1024x1024.webp 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>The <strong>load average</strong> is a critical metric in Linux, offering insights into system performance and workload. However, it&#8217;s often misunderstood. What does it mean when the load average is 1.5, 5.0, or 10.0? How do you interpret these numbers, and what do they indicate about system health? In this blog, we&#8217;ll demystify load average, explain how it&#8217;s calculated, and provide actionable steps for analysis and troubleshooting.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">GOPAKUMAR RAJAPPAN is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><div><hr></div><h3><strong>What Is Load Average?</strong></h3><p>Load average is a measure of the average number of processes that are:</p><ol><li><p><strong>Running</strong>: Actively using the CPU.</p></li><li><p><strong>Waiting</strong>: Ready to execute but waiting for CPU time.</p></li><li><p><strong>Uninterruptible Sleep</strong>: Stuck in I/O operations (e.g., waiting for disk or network resources).</p></li></ol><h4><strong>Where Is It Found?</strong></h4><p>The load average is displayed in the output of commands like <code>top</code><em>, </em><code>uptime</code><em>,</em> or <code>proc/loadavg</code>.</p><p>Example from <code>uptime</code>:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!s2HK!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc05e79f-a1d4-4593-b97c-70f24028ec5c_838x77.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!s2HK!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc05e79f-a1d4-4593-b97c-70f24028ec5c_838x77.png 424w, https://substackcdn.com/image/fetch/$s_!s2HK!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc05e79f-a1d4-4593-b97c-70f24028ec5c_838x77.png 848w, https://substackcdn.com/image/fetch/$s_!s2HK!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc05e79f-a1d4-4593-b97c-70f24028ec5c_838x77.png 1272w, https://substackcdn.com/image/fetch/$s_!s2HK!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc05e79f-a1d4-4593-b97c-70f24028ec5c_838x77.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!s2HK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc05e79f-a1d4-4593-b97c-70f24028ec5c_838x77.png" width="838" height="77" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/dc05e79f-a1d4-4593-b97c-70f24028ec5c_838x77.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:77,&quot;width&quot;:838,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:5470,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!s2HK!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc05e79f-a1d4-4593-b97c-70f24028ec5c_838x77.png 424w, https://substackcdn.com/image/fetch/$s_!s2HK!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc05e79f-a1d4-4593-b97c-70f24028ec5c_838x77.png 848w, https://substackcdn.com/image/fetch/$s_!s2HK!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc05e79f-a1d4-4593-b97c-70f24028ec5c_838x77.png 1272w, https://substackcdn.com/image/fetch/$s_!s2HK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc05e79f-a1d4-4593-b97c-70f24028ec5c_838x77.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><h4><strong>What Do the Three Numbers Represent?</strong></h4><ul><li><p><strong>1.00</strong>: Average load over the last 1 minute.</p></li><li><p><strong>0.75</strong>: Average load over the last 5 minutes.</p></li><li><p><strong>0.50</strong>: Average load over the last 15 minutes.</p></li></ul><div><hr></div><h3><strong>How to Interpret Load Average</strong></h3><ol><li><p><strong>Understanding CPU Capacity</strong>:</p><ul><li><p>A load average of <code>1.0</code> on a single-core system means the CPU is fully utilized.</p></li><li><p>On a multi-core system, divide the load average by the number of CPU cores to determine utilization. For example:</p><ul><li><p>On a 4-core system, a load average of <code>4.0</code> means the CPU is fully utilized.</p></li></ul></li></ul></li><li><p><strong>Evaluating System Health</strong>:</p><ul><li><p><strong>Healthy Load</strong>:</p><ul><li><p>The load average is less than or equal to the number of CPU cores.</p></li></ul></li><li><p><strong>Moderate Load</strong>:</p><ul><li><p>The load average exceeds the number of CPU cores but the system remains responsive.</p></li></ul></li><li><p><strong>High Load</strong>:</p><ul><li><p>The load average significantly exceeds the number of CPU cores, indicating potential bottlenecks.</p></li></ul></li></ul></li></ol><div><hr></div><h3><strong>Why Load Average Matters</strong></h3><ol><li><p><strong>Performance Monitoring</strong>:</p><ul><li><p>High load averages may indicate overutilization, I/O bottlenecks, or inefficient processes.</p></li></ul></li><li><p><strong>Resource Planning</strong>:</p><ul><li><p>Load average helps in deciding when to scale resources or optimize workloads.</p></li></ul></li><li><p><strong>Troubleshooting</strong>:</p><ul><li><p>A sudden spike in load average often points to specific issues like CPU-bound processes or disk contention.</p></li></ul></li></ol><div><hr></div><h3><strong>Common Causes of High Load Average</strong></h3><ol><li><p><strong>CPU Overload</strong>:</p><ul><li><p>Too many processes are competing for CPU time.</p></li><li><p>Identify with:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!869q!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04420786-6814-4e3d-bb14-c30421e78b42_767x37.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!869q!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04420786-6814-4e3d-bb14-c30421e78b42_767x37.png 424w, https://substackcdn.com/image/fetch/$s_!869q!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04420786-6814-4e3d-bb14-c30421e78b42_767x37.png 848w, https://substackcdn.com/image/fetch/$s_!869q!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04420786-6814-4e3d-bb14-c30421e78b42_767x37.png 1272w, https://substackcdn.com/image/fetch/$s_!869q!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04420786-6814-4e3d-bb14-c30421e78b42_767x37.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!869q!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04420786-6814-4e3d-bb14-c30421e78b42_767x37.png" width="767" height="37" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/04420786-6814-4e3d-bb14-c30421e78b42_767x37.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:37,&quot;width&quot;:767,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1513,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!869q!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04420786-6814-4e3d-bb14-c30421e78b42_767x37.png 424w, https://substackcdn.com/image/fetch/$s_!869q!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04420786-6814-4e3d-bb14-c30421e78b42_767x37.png 848w, https://substackcdn.com/image/fetch/$s_!869q!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04420786-6814-4e3d-bb14-c30421e78b42_767x37.png 1272w, https://substackcdn.com/image/fetch/$s_!869q!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04420786-6814-4e3d-bb14-c30421e78b42_767x37.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div></li></ul></li><li><p><strong>I/O Bottlenecks</strong>:</p><ul><li><p>Processes stuck in uninterruptible sleep due to disk or network I/O.</p></li><li><p>Check with:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!CDDn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3747f370-d6fd-4fae-9ec8-c87d140d7169_787x36.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!CDDn!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3747f370-d6fd-4fae-9ec8-c87d140d7169_787x36.png 424w, https://substackcdn.com/image/fetch/$s_!CDDn!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3747f370-d6fd-4fae-9ec8-c87d140d7169_787x36.png 848w, https://substackcdn.com/image/fetch/$s_!CDDn!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3747f370-d6fd-4fae-9ec8-c87d140d7169_787x36.png 1272w, https://substackcdn.com/image/fetch/$s_!CDDn!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3747f370-d6fd-4fae-9ec8-c87d140d7169_787x36.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!CDDn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3747f370-d6fd-4fae-9ec8-c87d140d7169_787x36.png" width="787" height="36" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3747f370-d6fd-4fae-9ec8-c87d140d7169_787x36.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:36,&quot;width&quot;:787,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1251,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!CDDn!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3747f370-d6fd-4fae-9ec8-c87d140d7169_787x36.png 424w, https://substackcdn.com/image/fetch/$s_!CDDn!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3747f370-d6fd-4fae-9ec8-c87d140d7169_787x36.png 848w, https://substackcdn.com/image/fetch/$s_!CDDn!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3747f370-d6fd-4fae-9ec8-c87d140d7169_787x36.png 1272w, https://substackcdn.com/image/fetch/$s_!CDDn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3747f370-d6fd-4fae-9ec8-c87d140d7169_787x36.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div></li></ul></li><li><p><strong>Memory Constraints</strong>:</p><ul><li><p>Insufficient RAM leading to excessive swapping.</p></li><li><p>Check swap usage:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!X2aU!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa3ca55f3-19ee-4e8a-8b3b-c3fc26d2d1f9_767x47.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!X2aU!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa3ca55f3-19ee-4e8a-8b3b-c3fc26d2d1f9_767x47.png 424w, https://substackcdn.com/image/fetch/$s_!X2aU!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa3ca55f3-19ee-4e8a-8b3b-c3fc26d2d1f9_767x47.png 848w, https://substackcdn.com/image/fetch/$s_!X2aU!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa3ca55f3-19ee-4e8a-8b3b-c3fc26d2d1f9_767x47.png 1272w, https://substackcdn.com/image/fetch/$s_!X2aU!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa3ca55f3-19ee-4e8a-8b3b-c3fc26d2d1f9_767x47.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!X2aU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa3ca55f3-19ee-4e8a-8b3b-c3fc26d2d1f9_767x47.png" width="767" height="47" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a3ca55f3-19ee-4e8a-8b3b-c3fc26d2d1f9_767x47.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:47,&quot;width&quot;:767,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1057,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!X2aU!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa3ca55f3-19ee-4e8a-8b3b-c3fc26d2d1f9_767x47.png 424w, https://substackcdn.com/image/fetch/$s_!X2aU!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa3ca55f3-19ee-4e8a-8b3b-c3fc26d2d1f9_767x47.png 848w, https://substackcdn.com/image/fetch/$s_!X2aU!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa3ca55f3-19ee-4e8a-8b3b-c3fc26d2d1f9_767x47.png 1272w, https://substackcdn.com/image/fetch/$s_!X2aU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa3ca55f3-19ee-4e8a-8b3b-c3fc26d2d1f9_767x47.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div></li></ul></li><li><p><strong>Misbehaving Processes</strong>:</p><ul><li><p>Runaway processes consuming resources.</p></li><li><p>Identify with:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!MgEb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06317c19-f775-481b-9595-7926dd26bf20_767x42.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!MgEb!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06317c19-f775-481b-9595-7926dd26bf20_767x42.png 424w, https://substackcdn.com/image/fetch/$s_!MgEb!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06317c19-f775-481b-9595-7926dd26bf20_767x42.png 848w, https://substackcdn.com/image/fetch/$s_!MgEb!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06317c19-f775-481b-9595-7926dd26bf20_767x42.png 1272w, https://substackcdn.com/image/fetch/$s_!MgEb!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06317c19-f775-481b-9595-7926dd26bf20_767x42.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!MgEb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06317c19-f775-481b-9595-7926dd26bf20_767x42.png" width="767" height="42" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/06317c19-f775-481b-9595-7926dd26bf20_767x42.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:42,&quot;width&quot;:767,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2217,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!MgEb!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06317c19-f775-481b-9595-7926dd26bf20_767x42.png 424w, https://substackcdn.com/image/fetch/$s_!MgEb!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06317c19-f775-481b-9595-7926dd26bf20_767x42.png 848w, https://substackcdn.com/image/fetch/$s_!MgEb!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06317c19-f775-481b-9595-7926dd26bf20_767x42.png 1272w, https://substackcdn.com/image/fetch/$s_!MgEb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06317c19-f775-481b-9595-7926dd26bf20_767x42.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div></li></ul></li></ol><p></p><h3><strong>Best Practices</strong></h3><ol><li><p><strong>Set Realistic Thresholds</strong>:</p><ul><li><p>Define acceptable load averages based on your system&#8217;s CPU and I/O capacity.</p></li></ul></li><li><p><strong>Scale Resources</strong>:</p><ul><li><p>Add CPUs, optimize disk I/O, or distribute workloads across servers when load exceeds capacity.</p></li></ul></li><li><p><strong>Automate Alerts</strong>:</p><ul><li><p>Configure alerts for high load averages using tools like Nagios, Zabbix, or Grafana.</p></li></ul></li><li><p><strong>Plan for Peaks</strong>:</p><ul><li><p>Use load testing tools to anticipate peak loads and optimize application performance.</p></li></ul></li></ol><div><hr></div><h3><strong>Conclusion</strong></h3><p>Load average is a powerful metric that provides a high-level view of system activity and performance. By understanding how to interpret and analyze it, you can identify potential bottlenecks, troubleshoot issues, and plan resource scaling effectively. Whether you&#8217;re an administrator monitoring servers or a developer optimizing applications, mastering load average is a key step in managing Linux systems efficiently.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">GOPAKUMAR RAJAPPAN is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Hard links and their limitations]]></title><description><![CDATA[Hard Links and Their Limits]]></description><link>https://www.gopakumar-rajappan.com/p/hard-links-and-their-limitations</link><guid isPermaLink="false">https://www.gopakumar-rajappan.com/p/hard-links-and-their-limitations</guid><dc:creator><![CDATA[GOPAKUMAR RAJAPPAN]]></dc:creator><pubDate>Tue, 10 Dec 2024 00:26:08 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!nq47!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27212d10-9e44-45f2-8595-01725067e59b_916x595.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3>Hard Links and Their Limits</h3><p>A <strong>hard link</strong> is like giving a file an extra name that points to the exact same data on the disk. When you create a hard link, you're not copying the file; you're just creating another way to access the same file content.</p><p>However, there are two important limits to what hard links can do:</p><ol><li><p><strong>Cannot span across file systems:</strong></p><ul><li><p>Think of a file system like a separate container (e.g., your <code>/home</code> directory might be on one disk or partition, and <code>/mnt/usb</code> on another).</p></li><li><p>A hard link must stay inside the same container because it points directly to the physical location of data on the disk. If the data is on another file system, the hard link doesn't know how to reach it.</p></li></ul></li><li><p><strong>Cannot span across directories (in some cases):</strong></p><ul><li><p>Traditionally, hard links can't be made to directories because it could create circular paths and confuse the system about the file structure.</p></li><li><p>This limitation is more about maintaining the organization and safety of the file system.</p></li></ul></li></ol><p>So, in summary:</p><ul><li><p>Hard links are like extra names for a file, but they only work within the same "container" (file system).</p></li><li><p>They typically can't link to directories to keep the file system orderly.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!nq47!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27212d10-9e44-45f2-8595-01725067e59b_916x595.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!nq47!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27212d10-9e44-45f2-8595-01725067e59b_916x595.webp 424w, https://substackcdn.com/image/fetch/$s_!nq47!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27212d10-9e44-45f2-8595-01725067e59b_916x595.webp 848w, https://substackcdn.com/image/fetch/$s_!nq47!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27212d10-9e44-45f2-8595-01725067e59b_916x595.webp 1272w, https://substackcdn.com/image/fetch/$s_!nq47!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27212d10-9e44-45f2-8595-01725067e59b_916x595.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!nq47!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27212d10-9e44-45f2-8595-01725067e59b_916x595.webp" width="916" height="595" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/27212d10-9e44-45f2-8595-01725067e59b_916x595.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:595,&quot;width&quot;:916,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:21242,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/webp&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!nq47!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27212d10-9e44-45f2-8595-01725067e59b_916x595.webp 424w, https://substackcdn.com/image/fetch/$s_!nq47!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27212d10-9e44-45f2-8595-01725067e59b_916x595.webp 848w, https://substackcdn.com/image/fetch/$s_!nq47!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27212d10-9e44-45f2-8595-01725067e59b_916x595.webp 1272w, https://substackcdn.com/image/fetch/$s_!nq47!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27212d10-9e44-45f2-8595-01725067e59b_916x595.webp 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p></li></ul><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">GOPAKUMAR RAJAPPAN is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Linux Files: Storage, Management, and Troubleshooting]]></title><description><![CDATA[Files are at the heart of any operating system, and Linux treats everything&#8212;from documents to devices&#8212;as files.]]></description><link>https://www.gopakumar-rajappan.com/p/linux-files-storage-management-and</link><guid isPermaLink="false">https://www.gopakumar-rajappan.com/p/linux-files-storage-management-and</guid><dc:creator><![CDATA[GOPAKUMAR RAJAPPAN]]></dc:creator><pubDate>Sun, 08 Dec 2024 04:12:11 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!1EAP!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5822ffa0-926f-4f9d-a562-093c75cefdb4_1832x986.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Files are at the heart of any operating system, and Linux treats everything&#8212;from documents to devices&#8212;as files. Understanding how files are stored, managed, and linked is crucial for system administrators and developers alike. This blog dives into the concepts of file storage, inodes, soft and hard links, their implications, and troubleshooting techniques to identify root causes of file-related issues.</p><div><hr></div><h3><strong>How Files Are Stored in Linux</strong></h3><ol><li><p><strong>File System Overview</strong>:</p><ul><li><p>Linux files are stored in a hierarchical directory structure.</p></li><li><p>Each file or directory is represented by metadata (information about the file) and its actual data.</p></li></ul></li><li><p><strong>Data and Metadata</strong>:</p><ul><li><p><strong>Data</strong>: The content of the file is stored in data blocks on the disk.</p></li><li><p><strong>Metadata</strong>: Information about the file (e.g., permissions, owner, timestamps, size) is stored in an <strong>inode</strong> (index node).</p></li></ul></li><li><p><strong>Role of the Kernel</strong>:</p><ul><li><p>The kernel manages file operations through the <strong>Virtual File System (VFS)</strong>, which abstracts underlying file systems (e.g., ext4, xfs).</p></li><li><p>It translates user-level file operations (<code>open</code>, <code>read</code>, <code>write</code>) into disk-level operations.</p></li></ul></li></ol><div><hr></div><h3><strong>What is an Inode?</strong></h3><p>An <strong>inode</strong> is a data structure that stores metadata about a file or directory. Each file has a unique inode, except in the case of hard links.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">GOPAKUMAR RAJAPPAN is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h4><strong>Information Stored in an Inode</strong>:</h4><ul><li><p>File type (regular file, directory, etc.)</p></li><li><p>Permissions</p></li><li><p>Owner (UID) and group (GID)</p></li><li><p>File size</p></li><li><p>Timestamps (creation, access, modification)</p></li><li><p>Pointers to data blocks on the disk</p></li></ul><h4><strong>What Inodes Don&#8217;t Store</strong>:</h4><ul><li><p>File name: The directory structure maps file names to inodes.</p></li></ul><h4><strong>Checking Inodes</strong>:</h4><p>Use <code>ls</code> with the <code>-i</code> flag to view the inode number of a file:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ZuKq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1287b2bc-cd3a-4947-895f-94caf3e4fc8c_873x40.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ZuKq!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1287b2bc-cd3a-4947-895f-94caf3e4fc8c_873x40.png 424w, https://substackcdn.com/image/fetch/$s_!ZuKq!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1287b2bc-cd3a-4947-895f-94caf3e4fc8c_873x40.png 848w, https://substackcdn.com/image/fetch/$s_!ZuKq!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1287b2bc-cd3a-4947-895f-94caf3e4fc8c_873x40.png 1272w, https://substackcdn.com/image/fetch/$s_!ZuKq!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1287b2bc-cd3a-4947-895f-94caf3e4fc8c_873x40.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ZuKq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1287b2bc-cd3a-4947-895f-94caf3e4fc8c_873x40.png" width="873" height="40" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1287b2bc-cd3a-4947-895f-94caf3e4fc8c_873x40.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:40,&quot;width&quot;:873,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1537,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ZuKq!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1287b2bc-cd3a-4947-895f-94caf3e4fc8c_873x40.png 424w, https://substackcdn.com/image/fetch/$s_!ZuKq!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1287b2bc-cd3a-4947-895f-94caf3e4fc8c_873x40.png 848w, https://substackcdn.com/image/fetch/$s_!ZuKq!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1287b2bc-cd3a-4947-895f-94caf3e4fc8c_873x40.png 1272w, https://substackcdn.com/image/fetch/$s_!ZuKq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1287b2bc-cd3a-4947-895f-94caf3e4fc8c_873x40.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><h3><strong>Soft Links vs. Hard Links</strong></h3><p>Links are shortcuts or references to files. Linux supports two types: <strong>soft links</strong> and <strong>hard links</strong>.</p><h4><strong>Soft Links (Symbolic Links)</strong>:</h4><ul><li><p>A soft link is like a shortcut that points to the original file.</p></li><li><p>If the original file is deleted, the soft link becomes broken.</p></li><li><p>Soft links can span across file systems.</p></li></ul><p><strong>Example</strong>:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!b0sP!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fc8b6e5-146c-417f-86cd-fd7efdea1dfa_861x48.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!b0sP!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fc8b6e5-146c-417f-86cd-fd7efdea1dfa_861x48.png 424w, https://substackcdn.com/image/fetch/$s_!b0sP!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fc8b6e5-146c-417f-86cd-fd7efdea1dfa_861x48.png 848w, https://substackcdn.com/image/fetch/$s_!b0sP!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fc8b6e5-146c-417f-86cd-fd7efdea1dfa_861x48.png 1272w, https://substackcdn.com/image/fetch/$s_!b0sP!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fc8b6e5-146c-417f-86cd-fd7efdea1dfa_861x48.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!b0sP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fc8b6e5-146c-417f-86cd-fd7efdea1dfa_861x48.png" width="861" height="48" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5fc8b6e5-146c-417f-86cd-fd7efdea1dfa_861x48.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:48,&quot;width&quot;:861,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2238,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!b0sP!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fc8b6e5-146c-417f-86cd-fd7efdea1dfa_861x48.png 424w, https://substackcdn.com/image/fetch/$s_!b0sP!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fc8b6e5-146c-417f-86cd-fd7efdea1dfa_861x48.png 848w, https://substackcdn.com/image/fetch/$s_!b0sP!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fc8b6e5-146c-417f-86cd-fd7efdea1dfa_861x48.png 1272w, https://substackcdn.com/image/fetch/$s_!b0sP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fc8b6e5-146c-417f-86cd-fd7efdea1dfa_861x48.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!1EAP!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5822ffa0-926f-4f9d-a562-093c75cefdb4_1832x986.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!1EAP!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5822ffa0-926f-4f9d-a562-093c75cefdb4_1832x986.png 424w, https://substackcdn.com/image/fetch/$s_!1EAP!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5822ffa0-926f-4f9d-a562-093c75cefdb4_1832x986.png 848w, https://substackcdn.com/image/fetch/$s_!1EAP!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5822ffa0-926f-4f9d-a562-093c75cefdb4_1832x986.png 1272w, https://substackcdn.com/image/fetch/$s_!1EAP!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5822ffa0-926f-4f9d-a562-093c75cefdb4_1832x986.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!1EAP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5822ffa0-926f-4f9d-a562-093c75cefdb4_1832x986.png" width="1456" height="784" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5822ffa0-926f-4f9d-a562-093c75cefdb4_1832x986.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:784,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:95121,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!1EAP!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5822ffa0-926f-4f9d-a562-093c75cefdb4_1832x986.png 424w, https://substackcdn.com/image/fetch/$s_!1EAP!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5822ffa0-926f-4f9d-a562-093c75cefdb4_1832x986.png 848w, https://substackcdn.com/image/fetch/$s_!1EAP!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5822ffa0-926f-4f9d-a562-093c75cefdb4_1832x986.png 1272w, https://substackcdn.com/image/fetch/$s_!1EAP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5822ffa0-926f-4f9d-a562-093c75cefdb4_1832x986.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><h4><strong>Hard Links</strong>:</h4><ul><li><p>A hard link is a direct reference to the inode of the original file.</p></li><li><p>Both the original file and the hard link share the same inode, meaning they are indistinguishable.</p></li><li><p>If the original file is deleted, the data remains accessible through the hard link.</p></li><li><p><a href="https://open.substack.com/pub/gopakumarrajappan/p/hard-links-and-their-limitations?r=1vvg49&amp;utm_campaign=post&amp;utm_medium=web&amp;showWelcomeOnShare=true">Hard links cannot span across file systems or directories.</a></p></li></ul><p><strong>Example</strong>:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!PbCf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5498a93-a193-42da-b52f-2d979d0d651b_847x32.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!PbCf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5498a93-a193-42da-b52f-2d979d0d651b_847x32.png 424w, https://substackcdn.com/image/fetch/$s_!PbCf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5498a93-a193-42da-b52f-2d979d0d651b_847x32.png 848w, https://substackcdn.com/image/fetch/$s_!PbCf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5498a93-a193-42da-b52f-2d979d0d651b_847x32.png 1272w, https://substackcdn.com/image/fetch/$s_!PbCf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5498a93-a193-42da-b52f-2d979d0d651b_847x32.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!PbCf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5498a93-a193-42da-b52f-2d979d0d651b_847x32.png" width="847" height="32" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c5498a93-a193-42da-b52f-2d979d0d651b_847x32.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:32,&quot;width&quot;:847,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2014,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!PbCf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5498a93-a193-42da-b52f-2d979d0d651b_847x32.png 424w, https://substackcdn.com/image/fetch/$s_!PbCf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5498a93-a193-42da-b52f-2d979d0d651b_847x32.png 848w, https://substackcdn.com/image/fetch/$s_!PbCf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5498a93-a193-42da-b52f-2d979d0d651b_847x32.png 1272w, https://substackcdn.com/image/fetch/$s_!PbCf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5498a93-a193-42da-b52f-2d979d0d651b_847x32.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!B-_H!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc220ee4e-9b04-479c-9e4c-7d5041d07404_1868x1021.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!B-_H!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc220ee4e-9b04-479c-9e4c-7d5041d07404_1868x1021.png 424w, https://substackcdn.com/image/fetch/$s_!B-_H!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc220ee4e-9b04-479c-9e4c-7d5041d07404_1868x1021.png 848w, https://substackcdn.com/image/fetch/$s_!B-_H!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc220ee4e-9b04-479c-9e4c-7d5041d07404_1868x1021.png 1272w, https://substackcdn.com/image/fetch/$s_!B-_H!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc220ee4e-9b04-479c-9e4c-7d5041d07404_1868x1021.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!B-_H!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc220ee4e-9b04-479c-9e4c-7d5041d07404_1868x1021.png" width="1456" height="796" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c220ee4e-9b04-479c-9e4c-7d5041d07404_1868x1021.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:796,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:84956,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!B-_H!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc220ee4e-9b04-479c-9e4c-7d5041d07404_1868x1021.png 424w, https://substackcdn.com/image/fetch/$s_!B-_H!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc220ee4e-9b04-479c-9e4c-7d5041d07404_1868x1021.png 848w, https://substackcdn.com/image/fetch/$s_!B-_H!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc220ee4e-9b04-479c-9e4c-7d5041d07404_1868x1021.png 1272w, https://substackcdn.com/image/fetch/$s_!B-_H!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc220ee4e-9b04-479c-9e4c-7d5041d07404_1868x1021.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!hmoC!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4428484b-86a9-4ba8-b1e9-6f53c74629a6_907x257.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!hmoC!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4428484b-86a9-4ba8-b1e9-6f53c74629a6_907x257.png 424w, https://substackcdn.com/image/fetch/$s_!hmoC!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4428484b-86a9-4ba8-b1e9-6f53c74629a6_907x257.png 848w, https://substackcdn.com/image/fetch/$s_!hmoC!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4428484b-86a9-4ba8-b1e9-6f53c74629a6_907x257.png 1272w, https://substackcdn.com/image/fetch/$s_!hmoC!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4428484b-86a9-4ba8-b1e9-6f53c74629a6_907x257.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!hmoC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4428484b-86a9-4ba8-b1e9-6f53c74629a6_907x257.png" width="907" height="257" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4428484b-86a9-4ba8-b1e9-6f53c74629a6_907x257.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:257,&quot;width&quot;:907,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:22680,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!hmoC!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4428484b-86a9-4ba8-b1e9-6f53c74629a6_907x257.png 424w, https://substackcdn.com/image/fetch/$s_!hmoC!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4428484b-86a9-4ba8-b1e9-6f53c74629a6_907x257.png 848w, https://substackcdn.com/image/fetch/$s_!hmoC!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4428484b-86a9-4ba8-b1e9-6f53c74629a6_907x257.png 1272w, https://substackcdn.com/image/fetch/$s_!hmoC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4428484b-86a9-4ba8-b1e9-6f53c74629a6_907x257.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3><strong>Implications on Storage</strong></h3><ol><li><p><strong>Inode Exhaustion</strong>:</p><ul><li><p>Even if you have free disk space, running out of inodes can prevent new files from being created.</p></li><li><p>Check inode usage:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!S2cG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13cca115-fbf6-4dd2-b4c3-da611df90618_787x40.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!S2cG!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13cca115-fbf6-4dd2-b4c3-da611df90618_787x40.png 424w, https://substackcdn.com/image/fetch/$s_!S2cG!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13cca115-fbf6-4dd2-b4c3-da611df90618_787x40.png 848w, https://substackcdn.com/image/fetch/$s_!S2cG!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13cca115-fbf6-4dd2-b4c3-da611df90618_787x40.png 1272w, https://substackcdn.com/image/fetch/$s_!S2cG!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13cca115-fbf6-4dd2-b4c3-da611df90618_787x40.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!S2cG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13cca115-fbf6-4dd2-b4c3-da611df90618_787x40.png" width="787" height="40" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/13cca115-fbf6-4dd2-b4c3-da611df90618_787x40.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:40,&quot;width&quot;:787,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:853,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!S2cG!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13cca115-fbf6-4dd2-b4c3-da611df90618_787x40.png 424w, https://substackcdn.com/image/fetch/$s_!S2cG!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13cca115-fbf6-4dd2-b4c3-da611df90618_787x40.png 848w, https://substackcdn.com/image/fetch/$s_!S2cG!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13cca115-fbf6-4dd2-b4c3-da611df90618_787x40.png 1272w, https://substackcdn.com/image/fetch/$s_!S2cG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13cca115-fbf6-4dd2-b4c3-da611df90618_787x40.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div></li></ul></li><li><p><strong>File Deletion</strong>:</p><ul><li><p>Deleting a file only reduces the link count of its inode. The data is only removed when the link count reaches zero (no hard links remain).</p></li></ul></li><li><p><strong>Data Fragmentation</strong>:</p><ul><li><p>Over time, data blocks of a file may become fragmented, leading to slower access.</p></li></ul></li></ol><h3><strong>Troubleshooting File-Related Issues</strong></h3><h4><strong>1. Missing Files</strong></h4><ul><li><p><strong>Symptom</strong>: A file is inaccessible, or a soft link is broken.</p></li><li><p><strong>Solution</strong>:</p><ul><li><p>Verify the link:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!2EpT!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34f29396-3dc2-4116-aadd-21665f94996b_772x36.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!2EpT!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34f29396-3dc2-4116-aadd-21665f94996b_772x36.png 424w, https://substackcdn.com/image/fetch/$s_!2EpT!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34f29396-3dc2-4116-aadd-21665f94996b_772x36.png 848w, https://substackcdn.com/image/fetch/$s_!2EpT!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34f29396-3dc2-4116-aadd-21665f94996b_772x36.png 1272w, https://substackcdn.com/image/fetch/$s_!2EpT!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34f29396-3dc2-4116-aadd-21665f94996b_772x36.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!2EpT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34f29396-3dc2-4116-aadd-21665f94996b_772x36.png" width="772" height="36" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/34f29396-3dc2-4116-aadd-21665f94996b_772x36.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:36,&quot;width&quot;:772,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1486,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!2EpT!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34f29396-3dc2-4116-aadd-21665f94996b_772x36.png 424w, https://substackcdn.com/image/fetch/$s_!2EpT!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34f29396-3dc2-4116-aadd-21665f94996b_772x36.png 848w, https://substackcdn.com/image/fetch/$s_!2EpT!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34f29396-3dc2-4116-aadd-21665f94996b_772x36.png 1272w, https://substackcdn.com/image/fetch/$s_!2EpT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34f29396-3dc2-4116-aadd-21665f94996b_772x36.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div></li></ul></li></ul><h4><strong>2. Running Out of Inodes</strong></h4><ul><li><p><strong>Symptom</strong>: "No space left on device" error, even though <code>df</code> shows free disk space.</p></li><li><p><strong>Solution</strong>:</p><ul><li><p>Check inode usage:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!tDDl!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78168951-74fa-434a-bb45-9c3eeec6a44e_787x42.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!tDDl!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78168951-74fa-434a-bb45-9c3eeec6a44e_787x42.png 424w, https://substackcdn.com/image/fetch/$s_!tDDl!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78168951-74fa-434a-bb45-9c3eeec6a44e_787x42.png 848w, https://substackcdn.com/image/fetch/$s_!tDDl!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78168951-74fa-434a-bb45-9c3eeec6a44e_787x42.png 1272w, https://substackcdn.com/image/fetch/$s_!tDDl!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78168951-74fa-434a-bb45-9c3eeec6a44e_787x42.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!tDDl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78168951-74fa-434a-bb45-9c3eeec6a44e_787x42.png" width="787" height="42" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/78168951-74fa-434a-bb45-9c3eeec6a44e_787x42.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:42,&quot;width&quot;:787,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:864,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!tDDl!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78168951-74fa-434a-bb45-9c3eeec6a44e_787x42.png 424w, https://substackcdn.com/image/fetch/$s_!tDDl!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78168951-74fa-434a-bb45-9c3eeec6a44e_787x42.png 848w, https://substackcdn.com/image/fetch/$s_!tDDl!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78168951-74fa-434a-bb45-9c3eeec6a44e_787x42.png 1272w, https://substackcdn.com/image/fetch/$s_!tDDl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78168951-74fa-434a-bb45-9c3eeec6a44e_787x42.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div></li><li><p>Identify directories with excessive small files:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!yiGp!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd12f2940-d09c-40da-a9e5-bc249b24ffa3_776x42.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!yiGp!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd12f2940-d09c-40da-a9e5-bc249b24ffa3_776x42.png 424w, https://substackcdn.com/image/fetch/$s_!yiGp!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd12f2940-d09c-40da-a9e5-bc249b24ffa3_776x42.png 848w, https://substackcdn.com/image/fetch/$s_!yiGp!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd12f2940-d09c-40da-a9e5-bc249b24ffa3_776x42.png 1272w, https://substackcdn.com/image/fetch/$s_!yiGp!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd12f2940-d09c-40da-a9e5-bc249b24ffa3_776x42.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!yiGp!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd12f2940-d09c-40da-a9e5-bc249b24ffa3_776x42.png" width="776" height="42" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d12f2940-d09c-40da-a9e5-bc249b24ffa3_776x42.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:42,&quot;width&quot;:776,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:4512,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!yiGp!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd12f2940-d09c-40da-a9e5-bc249b24ffa3_776x42.png 424w, https://substackcdn.com/image/fetch/$s_!yiGp!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd12f2940-d09c-40da-a9e5-bc249b24ffa3_776x42.png 848w, https://substackcdn.com/image/fetch/$s_!yiGp!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd12f2940-d09c-40da-a9e5-bc249b24ffa3_776x42.png 1272w, https://substackcdn.com/image/fetch/$s_!yiGp!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd12f2940-d09c-40da-a9e5-bc249b24ffa3_776x42.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div></li></ul></li></ul><h4><strong>3. Resolving Storage Issues</strong></h4><ul><li><p><strong>Symptom</strong>: High disk usage despite no visible large files.</p></li><li><p><strong>Solution</strong>:</p><ul><li><p>Identify hidden or orphaned files using disk space:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!G0qh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe11438c7-cf92-4207-8a63-1c668b2a9722_782x45.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!G0qh!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe11438c7-cf92-4207-8a63-1c668b2a9722_782x45.png 424w, https://substackcdn.com/image/fetch/$s_!G0qh!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe11438c7-cf92-4207-8a63-1c668b2a9722_782x45.png 848w, https://substackcdn.com/image/fetch/$s_!G0qh!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe11438c7-cf92-4207-8a63-1c668b2a9722_782x45.png 1272w, https://substackcdn.com/image/fetch/$s_!G0qh!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe11438c7-cf92-4207-8a63-1c668b2a9722_782x45.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!G0qh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe11438c7-cf92-4207-8a63-1c668b2a9722_782x45.png" width="782" height="45" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e11438c7-cf92-4207-8a63-1c668b2a9722_782x45.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:45,&quot;width&quot;:782,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2231,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!G0qh!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe11438c7-cf92-4207-8a63-1c668b2a9722_782x45.png 424w, https://substackcdn.com/image/fetch/$s_!G0qh!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe11438c7-cf92-4207-8a63-1c668b2a9722_782x45.png 848w, https://substackcdn.com/image/fetch/$s_!G0qh!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe11438c7-cf92-4207-8a63-1c668b2a9722_782x45.png 1272w, https://substackcdn.com/image/fetch/$s_!G0qh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe11438c7-cf92-4207-8a63-1c668b2a9722_782x45.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div></li><li><p>Check for files open by processes:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!0RBF!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fead89ada-ab77-4332-a355-504283130236_762x42.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!0RBF!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fead89ada-ab77-4332-a355-504283130236_762x42.png 424w, https://substackcdn.com/image/fetch/$s_!0RBF!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fead89ada-ab77-4332-a355-504283130236_762x42.png 848w, https://substackcdn.com/image/fetch/$s_!0RBF!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fead89ada-ab77-4332-a355-504283130236_762x42.png 1272w, https://substackcdn.com/image/fetch/$s_!0RBF!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fead89ada-ab77-4332-a355-504283130236_762x42.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!0RBF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fead89ada-ab77-4332-a355-504283130236_762x42.png" width="762" height="42" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ead89ada-ab77-4332-a355-504283130236_762x42.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:42,&quot;width&quot;:762,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1070,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!0RBF!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fead89ada-ab77-4332-a355-504283130236_762x42.png 424w, https://substackcdn.com/image/fetch/$s_!0RBF!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fead89ada-ab77-4332-a355-504283130236_762x42.png 848w, https://substackcdn.com/image/fetch/$s_!0RBF!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fead89ada-ab77-4332-a355-504283130236_762x42.png 1272w, https://substackcdn.com/image/fetch/$s_!0RBF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fead89ada-ab77-4332-a355-504283130236_762x42.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div></li></ul></li></ul><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!TP1c!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76a6fc27-574e-45b6-94fd-3a2045a77318_912x388.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!TP1c!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76a6fc27-574e-45b6-94fd-3a2045a77318_912x388.png 424w, https://substackcdn.com/image/fetch/$s_!TP1c!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76a6fc27-574e-45b6-94fd-3a2045a77318_912x388.png 848w, https://substackcdn.com/image/fetch/$s_!TP1c!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76a6fc27-574e-45b6-94fd-3a2045a77318_912x388.png 1272w, https://substackcdn.com/image/fetch/$s_!TP1c!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76a6fc27-574e-45b6-94fd-3a2045a77318_912x388.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!TP1c!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76a6fc27-574e-45b6-94fd-3a2045a77318_912x388.png" width="912" height="388" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/76a6fc27-574e-45b6-94fd-3a2045a77318_912x388.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:388,&quot;width&quot;:912,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:29588,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!TP1c!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76a6fc27-574e-45b6-94fd-3a2045a77318_912x388.png 424w, https://substackcdn.com/image/fetch/$s_!TP1c!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76a6fc27-574e-45b6-94fd-3a2045a77318_912x388.png 848w, https://substackcdn.com/image/fetch/$s_!TP1c!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76a6fc27-574e-45b6-94fd-3a2045a77318_912x388.png 1272w, https://substackcdn.com/image/fetch/$s_!TP1c!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76a6fc27-574e-45b6-94fd-3a2045a77318_912x388.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3><strong>Conclusion</strong></h3><p>Linux&#8217;s file system is a robust mechanism for managing files and storage, with inodes at its core. Understanding the differences between soft and hard links, their implications on storage, and how to troubleshoot file-related issues equips you with the knowledge to manage Linux systems effectively. Whether you're diagnosing inode exhaustion, recovering deleted files, or optimizing storage usage, mastering these concepts will elevate your Linux skills.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">GOPAKUMAR RAJAPPAN is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Address Space in Linux]]></title><description><![CDATA[When a program runs in Linux, it is allocated an address space that organizes memory for various purposes.]]></description><link>https://www.gopakumar-rajappan.com/p/address-space-in-linux</link><guid isPermaLink="false">https://www.gopakumar-rajappan.com/p/address-space-in-linux</guid><dc:creator><![CDATA[GOPAKUMAR RAJAPPAN]]></dc:creator><pubDate>Sat, 07 Dec 2024 11:04:27 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!cW56!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8800589f-1483-4ffb-9310-1a05a89e177b_902x410.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When a program runs in Linux, it is allocated an <strong>address space</strong> that organizes memory for various purposes. This blog explains the structure of an address space, explores the roles of global variables, heap, stack, memory-mapped segments, and demonstrates these concepts with a simple example.</p><h3><strong>What Is Address Space?</strong></h3><p>An address space is the range of memory addresses assigned to a process by the operating system. This memory is divided into distinct regions, each serving a specific purpose.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">GOPAKUMAR RAJAPPAN is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h3><strong>Key Regions of Address Space</strong></h3><ol><li><p><strong>Text (Code) Segment</strong>:</p><ul><li><p>Contains the program&#8217;s executable code (instructions).</p></li><li><p>This segment is typically <strong>read-only</strong> to prevent accidental overwriting.</p></li></ul></li><li><p><strong>Data Segment</strong>:</p><ul><li><p>Stores global and static variables.</p></li><li><p>Subdivided into:</p><ul><li><p><strong>Initialized Data</strong>: Variables with initial values.</p></li><li><p><strong>Uninitialized Data (BSS)</strong>: Variables without initial values.</p></li></ul></li></ul></li><li><p><strong>Heap</strong>:</p><ul><li><p>Used for <strong>dynamic memory allocation</strong>.</p></li><li><p>Memory allocated at runtime grows upwards.</p></li></ul></li><li><p><strong>Stack</strong>:</p><ul><li><p>Stores local variables, function arguments, and return addresses.</p></li><li><p>Grows downwards with function calls.</p></li></ul></li><li><p><strong>Memory-Mapped Segment</strong>:</p><ul><li><p>Used for shared libraries, memory-mapped files, and hardware access.</p></li></ul></li></ol><h3><strong>Python Examples for Address Space Regions</strong></h3><h4><strong>1. Text (Code) Segment</strong></h4><p>The text segment contains the program&#8217;s executable code. In Python, functions and classes are stored in this region.</p><p><strong>Example</strong>:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Nr4g!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa6826c1e-9639-4a6b-80c4-0b8421cf862a_862x156.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Nr4g!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa6826c1e-9639-4a6b-80c4-0b8421cf862a_862x156.png 424w, https://substackcdn.com/image/fetch/$s_!Nr4g!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa6826c1e-9639-4a6b-80c4-0b8421cf862a_862x156.png 848w, https://substackcdn.com/image/fetch/$s_!Nr4g!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa6826c1e-9639-4a6b-80c4-0b8421cf862a_862x156.png 1272w, https://substackcdn.com/image/fetch/$s_!Nr4g!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa6826c1e-9639-4a6b-80c4-0b8421cf862a_862x156.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Nr4g!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa6826c1e-9639-4a6b-80c4-0b8421cf862a_862x156.png" width="862" height="156" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a6826c1e-9639-4a6b-80c4-0b8421cf862a_862x156.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:156,&quot;width&quot;:862,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:8024,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Nr4g!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa6826c1e-9639-4a6b-80c4-0b8421cf862a_862x156.png 424w, https://substackcdn.com/image/fetch/$s_!Nr4g!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa6826c1e-9639-4a6b-80c4-0b8421cf862a_862x156.png 848w, https://substackcdn.com/image/fetch/$s_!Nr4g!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa6826c1e-9639-4a6b-80c4-0b8421cf862a_862x156.png 1272w, https://substackcdn.com/image/fetch/$s_!Nr4g!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa6826c1e-9639-4a6b-80c4-0b8421cf862a_862x156.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><ul><li><p>The function <code>example_function</code> resides in the text segment.</p></li><li><p>It is immutable; modifying its bytecode would require advanced techniques (and isn&#8217;t recommended).</p></li></ul><div><hr></div><h4><strong>2. Data Segment</strong></h4><p>Global and static variables are stored in the data segment. While Python manages variables dynamically, we can mimic this behavior using global variables.</p><p><strong>Example</strong>:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!96RG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e864f78-49f3-4c94-8bfd-35395e827a62_870x200.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!96RG!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e864f78-49f3-4c94-8bfd-35395e827a62_870x200.png 424w, https://substackcdn.com/image/fetch/$s_!96RG!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e864f78-49f3-4c94-8bfd-35395e827a62_870x200.png 848w, https://substackcdn.com/image/fetch/$s_!96RG!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e864f78-49f3-4c94-8bfd-35395e827a62_870x200.png 1272w, https://substackcdn.com/image/fetch/$s_!96RG!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e864f78-49f3-4c94-8bfd-35395e827a62_870x200.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!96RG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e864f78-49f3-4c94-8bfd-35395e827a62_870x200.png" width="870" height="200" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0e864f78-49f3-4c94-8bfd-35395e827a62_870x200.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:200,&quot;width&quot;:870,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:12711,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!96RG!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e864f78-49f3-4c94-8bfd-35395e827a62_870x200.png 424w, https://substackcdn.com/image/fetch/$s_!96RG!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e864f78-49f3-4c94-8bfd-35395e827a62_870x200.png 848w, https://substackcdn.com/image/fetch/$s_!96RG!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e864f78-49f3-4c94-8bfd-35395e827a62_870x200.png 1272w, https://substackcdn.com/image/fetch/$s_!96RG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e864f78-49f3-4c94-8bfd-35395e827a62_870x200.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><ul><li><p><code>global_var</code> represents a variable stored in the initialized data section.</p></li><li><p>Uninitialized global variables (not common in Python) are analogous to the BSS segment.</p></li></ul><div><hr></div><h4><strong>3. Heap</strong></h4><p>The heap is used for dynamically allocated memory. In Python, all objects (lists, dictionaries, etc.) are dynamically allocated on the heap.</p><p><strong>Example</strong>:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!2Vgt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F83337131-3752-4814-aa2f-19cf2a8b773e_861x198.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!2Vgt!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F83337131-3752-4814-aa2f-19cf2a8b773e_861x198.png 424w, https://substackcdn.com/image/fetch/$s_!2Vgt!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F83337131-3752-4814-aa2f-19cf2a8b773e_861x198.png 848w, https://substackcdn.com/image/fetch/$s_!2Vgt!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F83337131-3752-4814-aa2f-19cf2a8b773e_861x198.png 1272w, https://substackcdn.com/image/fetch/$s_!2Vgt!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F83337131-3752-4814-aa2f-19cf2a8b773e_861x198.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!2Vgt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F83337131-3752-4814-aa2f-19cf2a8b773e_861x198.png" width="861" height="198" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/83337131-3752-4814-aa2f-19cf2a8b773e_861x198.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:198,&quot;width&quot;:861,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:15836,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!2Vgt!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F83337131-3752-4814-aa2f-19cf2a8b773e_861x198.png 424w, https://substackcdn.com/image/fetch/$s_!2Vgt!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F83337131-3752-4814-aa2f-19cf2a8b773e_861x198.png 848w, https://substackcdn.com/image/fetch/$s_!2Vgt!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F83337131-3752-4814-aa2f-19cf2a8b773e_861x198.png 1272w, https://substackcdn.com/image/fetch/$s_!2Vgt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F83337131-3752-4814-aa2f-19cf2a8b773e_861x198.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><ul><li><p><code>heap_list</code> and <code>heap_dict</code> are created dynamically, and their memory resides in the heap.</p></li><li><p>The <code>id</code> function returns the memory address of these objects.</p></li></ul><div><hr></div><h4><strong>4. Stack</strong></h4><p>The stack is used for managing function calls and local variables. Each function call creates a new stack frame.</p><p><strong>Example</strong>:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!dcsZ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7175041-8075-42cc-be18-945d5027b560_867x201.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!dcsZ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7175041-8075-42cc-be18-945d5027b560_867x201.png 424w, https://substackcdn.com/image/fetch/$s_!dcsZ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7175041-8075-42cc-be18-945d5027b560_867x201.png 848w, https://substackcdn.com/image/fetch/$s_!dcsZ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7175041-8075-42cc-be18-945d5027b560_867x201.png 1272w, https://substackcdn.com/image/fetch/$s_!dcsZ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7175041-8075-42cc-be18-945d5027b560_867x201.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!dcsZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7175041-8075-42cc-be18-945d5027b560_867x201.png" width="867" height="201" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a7175041-8075-42cc-be18-945d5027b560_867x201.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:201,&quot;width&quot;:867,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:11857,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!dcsZ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7175041-8075-42cc-be18-945d5027b560_867x201.png 424w, https://substackcdn.com/image/fetch/$s_!dcsZ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7175041-8075-42cc-be18-945d5027b560_867x201.png 848w, https://substackcdn.com/image/fetch/$s_!dcsZ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7175041-8075-42cc-be18-945d5027b560_867x201.png 1272w, https://substackcdn.com/image/fetch/$s_!dcsZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7175041-8075-42cc-be18-945d5027b560_867x201.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><ul><li><p>Each recursive call creates a stack frame containing the local variable <code>n</code>.</p></li><li><p>Excessive recursion can lead to a <strong>stack overflow</strong>.</p></li></ul><p><strong>Simulating Stack Overflow</strong>:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!rGZk!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe69bb04d-e228-4a64-a8aa-35d481798ac8_847x151.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!rGZk!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe69bb04d-e228-4a64-a8aa-35d481798ac8_847x151.png 424w, https://substackcdn.com/image/fetch/$s_!rGZk!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe69bb04d-e228-4a64-a8aa-35d481798ac8_847x151.png 848w, https://substackcdn.com/image/fetch/$s_!rGZk!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe69bb04d-e228-4a64-a8aa-35d481798ac8_847x151.png 1272w, https://substackcdn.com/image/fetch/$s_!rGZk!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe69bb04d-e228-4a64-a8aa-35d481798ac8_847x151.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!rGZk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe69bb04d-e228-4a64-a8aa-35d481798ac8_847x151.png" width="847" height="151" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e69bb04d-e228-4a64-a8aa-35d481798ac8_847x151.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:151,&quot;width&quot;:847,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:15751,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!rGZk!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe69bb04d-e228-4a64-a8aa-35d481798ac8_847x151.png 424w, https://substackcdn.com/image/fetch/$s_!rGZk!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe69bb04d-e228-4a64-a8aa-35d481798ac8_847x151.png 848w, https://substackcdn.com/image/fetch/$s_!rGZk!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe69bb04d-e228-4a64-a8aa-35d481798ac8_847x151.png 1272w, https://substackcdn.com/image/fetch/$s_!rGZk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe69bb04d-e228-4a64-a8aa-35d481798ac8_847x151.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><div><hr></div><h4><strong>5. Memory-Mapped Segment</strong></h4><p>Memory mapping allows files or devices to be mapped into memory, enabling efficient access. In Python, the <code>mmap</code> module provides this functionality.</p><p><strong>Example</strong>:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!gUbV!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79013ded-ecc6-44a6-9bda-8dc498209a74_857x218.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!gUbV!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79013ded-ecc6-44a6-9bda-8dc498209a74_857x218.png 424w, https://substackcdn.com/image/fetch/$s_!gUbV!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79013ded-ecc6-44a6-9bda-8dc498209a74_857x218.png 848w, https://substackcdn.com/image/fetch/$s_!gUbV!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79013ded-ecc6-44a6-9bda-8dc498209a74_857x218.png 1272w, https://substackcdn.com/image/fetch/$s_!gUbV!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79013ded-ecc6-44a6-9bda-8dc498209a74_857x218.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!gUbV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79013ded-ecc6-44a6-9bda-8dc498209a74_857x218.png" width="857" height="218" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/79013ded-ecc6-44a6-9bda-8dc498209a74_857x218.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:218,&quot;width&quot;:857,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:18981,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!gUbV!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79013ded-ecc6-44a6-9bda-8dc498209a74_857x218.png 424w, https://substackcdn.com/image/fetch/$s_!gUbV!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79013ded-ecc6-44a6-9bda-8dc498209a74_857x218.png 848w, https://substackcdn.com/image/fetch/$s_!gUbV!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79013ded-ecc6-44a6-9bda-8dc498209a74_857x218.png 1272w, https://substackcdn.com/image/fetch/$s_!gUbV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79013ded-ecc6-44a6-9bda-8dc498209a74_857x218.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><ul><li><p>This maps <code>example.txt</code> into memory, allowing direct access to its content.</p></li><li><p>Useful for large files or inter-process communication.</p></li></ul><div><hr></div><h3><strong>Detailed Memory Region Characteristics</strong></h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!cW56!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8800589f-1483-4ffb-9310-1a05a89e177b_902x410.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!cW56!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8800589f-1483-4ffb-9310-1a05a89e177b_902x410.png 424w, https://substackcdn.com/image/fetch/$s_!cW56!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8800589f-1483-4ffb-9310-1a05a89e177b_902x410.png 848w, https://substackcdn.com/image/fetch/$s_!cW56!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8800589f-1483-4ffb-9310-1a05a89e177b_902x410.png 1272w, https://substackcdn.com/image/fetch/$s_!cW56!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8800589f-1483-4ffb-9310-1a05a89e177b_902x410.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!cW56!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8800589f-1483-4ffb-9310-1a05a89e177b_902x410.png" width="902" height="410" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8800589f-1483-4ffb-9310-1a05a89e177b_902x410.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:410,&quot;width&quot;:902,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:42397,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!cW56!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8800589f-1483-4ffb-9310-1a05a89e177b_902x410.png 424w, https://substackcdn.com/image/fetch/$s_!cW56!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8800589f-1483-4ffb-9310-1a05a89e177b_902x410.png 848w, https://substackcdn.com/image/fetch/$s_!cW56!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8800589f-1483-4ffb-9310-1a05a89e177b_902x410.png 1272w, https://substackcdn.com/image/fetch/$s_!cW56!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8800589f-1483-4ffb-9310-1a05a89e177b_902x410.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3><strong>Conclusion</strong></h3><p>Understanding memory management and address space regions is crucial for optimizing application performance and debugging issues. Python or other high-level languages provides abstractions for many low-level concepts, but knowing how memory is organized helps write efficient and robust code.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">GOPAKUMAR RAJAPPAN is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Initial RAM Disk (initramfs) in Linux Boot Process]]></title><description><![CDATA[When your computer starts up, it goes through a series of steps to load the operating system.]]></description><link>https://www.gopakumar-rajappan.com/p/initial-ram-disk-initramfs-in-linux</link><guid isPermaLink="false">https://www.gopakumar-rajappan.com/p/initial-ram-disk-initramfs-in-linux</guid><dc:creator><![CDATA[GOPAKUMAR RAJAPPAN]]></dc:creator><pubDate>Sat, 07 Dec 2024 03:35:08 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!vfcd!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf3cbcd9-c01a-460e-9633-56bfcea12689_1792x1024.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!vfcd!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf3cbcd9-c01a-460e-9633-56bfcea12689_1792x1024.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!vfcd!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf3cbcd9-c01a-460e-9633-56bfcea12689_1792x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!vfcd!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf3cbcd9-c01a-460e-9633-56bfcea12689_1792x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!vfcd!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf3cbcd9-c01a-460e-9633-56bfcea12689_1792x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!vfcd!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf3cbcd9-c01a-460e-9633-56bfcea12689_1792x1024.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!vfcd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf3cbcd9-c01a-460e-9633-56bfcea12689_1792x1024.webp" width="1456" height="832" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bf3cbcd9-c01a-460e-9633-56bfcea12689_1792x1024.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:832,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:556344,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/webp&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!vfcd!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf3cbcd9-c01a-460e-9633-56bfcea12689_1792x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!vfcd!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf3cbcd9-c01a-460e-9633-56bfcea12689_1792x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!vfcd!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf3cbcd9-c01a-460e-9633-56bfcea12689_1792x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!vfcd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf3cbcd9-c01a-460e-9633-56bfcea12689_1792x1024.webp 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>When your computer starts up, it goes through a series of steps to load the operating system. One key element in this process is the <strong>Initial RAM Disk</strong> or <code>initramfs</code>. But what exactly is it, and how does it help get your system up and running? Let&#8217;s break it down in simple terms, focusing on how <code>initramfs</code> works, where it&#8217;s stored, and its role in the boot process.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">GOPAKUMAR RAJAPPAN is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h3>What is <code>initramfs</code>?</h3><p>The <strong>initramfs</strong> (Initial RAM File System) is a temporary file system stored in your computer's <strong>RAM</strong> (Random Access Memory) that gets loaded early during the boot process. It contains critical programs, files, and device drivers needed to start the system.</p><p>In other words, <code>initramfs</code> provides the <strong>bare minimum</strong> tools necessary to mount your real root file system and begin the full boot process. It makes sure that essential hardware, like storage devices, is accessible before the main operating system takes over.</p><h3>Where is <code>initramfs</code> Stored?</h3><p>The <code>initramfs</code> image is stored in the <strong>boot partition</strong> of your disk, typically in the <code>/boot</code> directory. It&#8217;s usually a compressed file (like <code>.cpio</code> or <code>.gz</code>) that&#8217;s loaded into memory by the bootloader. The bootloader is a small program responsible for starting up your system.</p><h3>How Does the Bootloader Load <code>initramfs</code>?</h3><p>Let&#8217;s follow the boot process to understand how the bootloader loads <code>initramfs</code>:</p><ol><li><p><strong>Bootloader Loads First</strong>: When you power on your computer, the <strong>bootloader</strong> (like GRUB) is the first program that runs. The bootloader is responsible for loading the kernel and <code>initramfs</code> into memory.</p></li><li><p><strong>Kernel and </strong><code>initramfs</code>: The bootloader reads its configuration to locate the kernel (the core part of the operating system) and the <code>initramfs</code> image. Both are loaded into memory.</p></li><li><p><strong>Kernel Starts Running</strong>: Once the kernel is loaded, it begins running. The kernel is responsible for managing hardware resources, and it needs the <code>initramfs</code> to access essential tools and drivers.</p></li><li><p><strong>Mounting the Root File System</strong>: The <code>initramfs</code> image contains a small program called <code>init</code> (not to be confused with the system&#8217;s main <code>init</code> program). The <code>init</code> program&#8217;s job is to find the <strong>real root file system</strong> (usually on your hard drive or SSD) and mount it. Before this can happen, it may need to load certain drivers and check for errors.</p></li><li><p><strong>Switching to the Real Root File System</strong>: Once the real root file system is mounted, the system can pivot from <code>initramfs</code> to the actual file system on your disk. At this point, <code>initramfs</code> is no longer needed and is cleared from memory.</p></li><li><p><strong>Full System Boot</strong>: Finally, the <strong>init program</strong> from the real root file system takes over, completing the boot process by starting system services and the user environment.</p></li></ol><h3>What Does <code>initramfs</code> Do?</h3><ul><li><p><strong>Kernel Functionality</strong>: The <code>initramfs</code> provides the kernel with the necessary functionality to interact with the root filesystem. This includes loading essential device drivers for hardware, such as storage devices and other peripherals.</p></li><li><p><strong>Device Drivers</strong>: It also includes drivers for mass storage controllers, which are responsible for managing storage devices like hard drives and SSDs. This is important because, without these drivers, the kernel wouldn&#8217;t be able to access your root file system or other essential storage.</p></li><li><p><strong>Udev System</strong>: The <code>initramfs</code> relies on <strong>udev</strong>, a system that dynamically detects the hardware connected to your computer. Udev finds the devices that are available (like disk drives) and loads the appropriate drivers to interact with them.</p></li></ul><h3>The Role of the <code>init</code> Program</h3><p>Once <code>initramfs</code> has successfully mounted the root file system, it runs a program called <strong>init</strong> (found at <code>/sbin/init</code> on your system). This program is responsible for setting up the system for normal operation. It continues the boot process by starting system services and preparing the system for user login.</p><p>If necessary, <code>init</code> can even load additional hardware drivers at this stage to ensure that all the system&#8217;s components are ready for use.</p><h3>Clearing <code>initramfs</code> from Memory</h3><p>After the root file system has been mounted and the real operating system is up and running, <code>initramfs</code> is no longer needed. The kernel removes it from memory to free up space for other tasks.</p><h3>Special Hardware Drivers in <code>initramfs</code></h3><p>If your computer requires <strong>special hardware drivers</strong> (like for RAID controllers, certain graphics cards, or other complex hardware), those drivers need to be included in the <code>initramfs</code> image. This ensures that the kernel can access all the hardware it needs to continue the boot process and mount the root file system.</p><h3>Conclusion</h3><p>The <strong>initramfs</strong> is a crucial part of the Linux boot process. By providing the essential tools and drivers in memory, it ensures that the system can mount the root file system and continue the boot process. Without <code>initramfs</code>, your computer might not be able to access storage devices or start up properly.</p><p>In simple terms, <code>initramfs</code> is like a helping hand that makes sure the kernel has everything it needs to load the operating system. Once the system is ready, it steps aside, allowing the full Linux environment to take over.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">GOPAKUMAR RAJAPPAN is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Memory Management in Linux]]></title><description><![CDATA[Memory management is one of the most critical functions of the Linux kernel.]]></description><link>https://www.gopakumar-rajappan.com/p/memory-management-in-linux</link><guid isPermaLink="false">https://www.gopakumar-rajappan.com/p/memory-management-in-linux</guid><dc:creator><![CDATA[GOPAKUMAR RAJAPPAN]]></dc:creator><pubDate>Fri, 29 Nov 2024 21:49:19 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!0BMm!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd74e8425-0a13-40ad-86b5-27bdf5afe57f_800x800.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Memory management is one of the most critical functions of the Linux kernel. It ensures that every process has the memory it needs to run while optimizing overall system performance. In this context, <strong>memory refers to RAM (Random Access Memory)</strong>, which is the fast, volatile memory used to store data and instructions currently being executed by the CPU. This is distinct from <strong>storage</strong>, which refers to hard disks, SSDs, or other non-volatile storage devices.</p><p>In this blog, we&#8217;ll explore how Linux manages memory, including its components, techniques, and tools. Let&#8217;s dive in.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">GOPAKUMAR RAJAPPAN is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h3><strong>What is Memory Management?</strong></h3><p><strong>Memory management</strong> is the kernel&#8217;s method of controlling and coordinating how memory (RAM) is allocated, used, and reclaimed. The kernel dynamically allocates memory to processes, ensures safe sharing of memory, and prevents processes from interfering with each other.</p><div><hr></div><h3><strong>Why is Memory Management Important?</strong></h3><ol><li><p><strong>Efficient Resource Utilization</strong>:</p><ul><li><p>RAM is limited and needs to be efficiently shared among processes.</p></li></ul></li><li><p><strong>Multitasking</strong>:</p><ul><li><p>Processes need isolated memory spaces to avoid conflicts and maintain security.</p></li></ul></li><li><p><strong>Performance Optimization</strong>:</p><ul><li><p>Proper memory management minimizes delays, avoids memory fragmentation, and ensures that frequently accessed data is kept in fast RAM.</p></li></ul></li></ol><div><hr></div><h3><strong>Key Concepts in Linux Memory Management</strong></h3><h4><strong>1. <a href="https://www.gopakumar-rajappan.com/p/virtual-memory-the-illusion-of-unlimited">Virtual Memory</a></strong></h4><h4><strong>2. <a href="https://www.gopakumar-rajappan.com/p/paging-in-linux-breaking-memory-into">Paging</a></strong></h4><h4><strong>3. <a href="https://www.gopakumar-rajappan.com/p/swapping-in-linux-extending-memory">Swapping</a></strong></h4><h4><strong>4. <a href="https://www.gopakumar-rajappan.com/p/cache-and-buffers">Cache and Buffers</a></strong></h4><div><hr></div><h4><strong>Memory Zones</strong></h4><p>The kernel divides physical memory into zones to handle hardware constraints:</p><ul><li><p><strong>DMA Zone</strong>: For legacy devices that can only access low memory (&lt;16 MB).</p></li><li><p><strong>Normal Zone</strong>: Usable memory for most kernel and user processes.</p></li><li><p><strong>High Memory Zone</strong>: Memory accessible only through special kernel mechanisms (e.g., on 32-bit systems).</p></li></ul><div><hr></div><h3><strong>How Linux Allocates Memory</strong></h3><h4><strong>1. Process Memory Layout</strong></h4><p>Each process has a structured memory layout:</p><ul><li><p><strong>Text Segment</strong>: Stores the program&#8217;s code (read-only).</p></li><li><p><strong>Data Segment</strong>: Stores global and static variables.</p></li><li><p><strong>Heap</strong>: Dynamically allocated memory (e.g., using <code>malloc()</code> in C).</p></li><li><p><strong>Stack</strong>: Stores function call information and local variables.</p></li><li><p><strong>Memory Mapped Segment</strong>: Used for shared libraries and memory-mapped files.</p></li></ul><p>Detailed information about process address space ( memory layout ) is available <a href="https://www.gopakumar-rajappan.com/p/address-space-in-linux">here</a>.</p><div><hr></div><h4><strong>2. Dynamic Memory Allocation</strong></h4><ul><li><p><strong>malloc()</strong>:</p><ul><li><p>Used by programs to request memory at runtime.</p></li><li><p>Allocates memory from the heap.</p></li></ul></li><li><p><strong>free()</strong>:</p><ul><li><p>Releases memory back to the system.</p></li></ul></li></ul><h4><strong>3. Kernel Memory Management</strong></h4><ul><li><p>The kernel allocates memory for its own data structures and buffers.</p></li><li><p><strong>Slab Allocator</strong>: Optimized for frequent allocations and deallocations of small memory objects.</p></li></ul><h3><strong>Process Memory States</strong></h3><p>Processes in Linux can hold memory in different states:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!pnQT!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb662125-094c-4411-ae34-1c4d7915f353_907x265.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!pnQT!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb662125-094c-4411-ae34-1c4d7915f353_907x265.png 424w, https://substackcdn.com/image/fetch/$s_!pnQT!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb662125-094c-4411-ae34-1c4d7915f353_907x265.png 848w, https://substackcdn.com/image/fetch/$s_!pnQT!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb662125-094c-4411-ae34-1c4d7915f353_907x265.png 1272w, https://substackcdn.com/image/fetch/$s_!pnQT!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb662125-094c-4411-ae34-1c4d7915f353_907x265.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!pnQT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb662125-094c-4411-ae34-1c4d7915f353_907x265.png" width="907" height="265" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cb662125-094c-4411-ae34-1c4d7915f353_907x265.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:265,&quot;width&quot;:907,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:26458,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!pnQT!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb662125-094c-4411-ae34-1c4d7915f353_907x265.png 424w, https://substackcdn.com/image/fetch/$s_!pnQT!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb662125-094c-4411-ae34-1c4d7915f353_907x265.png 848w, https://substackcdn.com/image/fetch/$s_!pnQT!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb662125-094c-4411-ae34-1c4d7915f353_907x265.png 1272w, https://substackcdn.com/image/fetch/$s_!pnQT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb662125-094c-4411-ae34-1c4d7915f353_907x265.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3><strong>Tools to Monitor Memory Usage</strong></h3><p>Linux provides several tools to monitor and debug memory usage:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!x4Cd!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32e7cae0-fbde-4edf-a96d-6cc9b6643527_907x268.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!x4Cd!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32e7cae0-fbde-4edf-a96d-6cc9b6643527_907x268.png 424w, https://substackcdn.com/image/fetch/$s_!x4Cd!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32e7cae0-fbde-4edf-a96d-6cc9b6643527_907x268.png 848w, https://substackcdn.com/image/fetch/$s_!x4Cd!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32e7cae0-fbde-4edf-a96d-6cc9b6643527_907x268.png 1272w, https://substackcdn.com/image/fetch/$s_!x4Cd!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32e7cae0-fbde-4edf-a96d-6cc9b6643527_907x268.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!x4Cd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32e7cae0-fbde-4edf-a96d-6cc9b6643527_907x268.png" width="907" height="268" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/32e7cae0-fbde-4edf-a96d-6cc9b6643527_907x268.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:268,&quot;width&quot;:907,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:27827,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!x4Cd!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32e7cae0-fbde-4edf-a96d-6cc9b6643527_907x268.png 424w, https://substackcdn.com/image/fetch/$s_!x4Cd!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32e7cae0-fbde-4edf-a96d-6cc9b6643527_907x268.png 848w, https://substackcdn.com/image/fetch/$s_!x4Cd!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32e7cae0-fbde-4edf-a96d-6cc9b6643527_907x268.png 1272w, https://substackcdn.com/image/fetch/$s_!x4Cd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32e7cae0-fbde-4edf-a96d-6cc9b6643527_907x268.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3><strong>Memory Lifecycle in Linux</strong></h3><p>Here&#8217;s a high-level view of how memory is managed through a process&#8217;s lifecycle:</p><ol><li><p><strong>Process Creation</strong>:</p><ul><li><p>The kernel allocates memory for the new process&#8217;s code, data, and stack.</p></li><li><p>Virtual memory mappings are established.</p></li></ul></li><li><p><strong>Execution</strong>:</p><ul><li><p>Pages are loaded into RAM as needed (on-demand paging).</p></li><li><p>The kernel caches frequently accessed data.</p></li></ul></li><li><p><strong>I/O Operations</strong>:</p><ul><li><p>Buffers are used for data being written to storage.</p></li><li><p>Cache is used to speed up repeated reads.</p></li></ul></li><li><p><strong>Termination</strong>:</p><ul><li><p>The kernel reclaims all memory used by the process.</p></li></ul></li></ol><div><hr></div><h3><strong>Recommendations</strong></h3><h4><strong>For Administrators</strong></h4><ol><li><p><strong>Monitor Memory</strong>:</p><ul><li><p>Use tools like <code>free</code>, <code>htop</code>, and <code>/proc/meminfo</code> to identify memory bottlenecks.</p></li></ul></li><li><p><strong>Manage Swap Space</strong>:</p><ul><li><p>Ensure sufficient swap space is available, but avoid over-reliance on it.</p></li></ul></li><li><p><strong>Use cgroups</strong>:</p><ul><li><p>Control memory usage of specific processes or groups of processes using cgroups.</p></li></ul></li></ol><div><hr></div><h3><strong>Conclusion</strong></h3><p>Memory management in Linux is a complex but essential process that ensures efficient use of RAM while maintaining system stability and performance. From virtual memory and paging to caching and swapping, the kernel employs sophisticated techniques to manage resources effectively. Whether you&#8217;re a developer optimizing an application or an administrator managing system performance, understanding Linux memory management is key to success.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">GOPAKUMAR RAJAPPAN is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Cache and Buffers]]></title><description><![CDATA[Cache and buffers in the context of Linux memory management are specific areas within RAM that the operating system uses for different purposes.]]></description><link>https://www.gopakumar-rajappan.com/p/cache-and-buffers</link><guid isPermaLink="false">https://www.gopakumar-rajappan.com/p/cache-and-buffers</guid><dc:creator><![CDATA[GOPAKUMAR RAJAPPAN]]></dc:creator><pubDate>Fri, 29 Nov 2024 21:43:03 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!abaU!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9f36808-dbf7-4bb1-8e82-67aab5f0b9fd_1024x1024.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!abaU!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9f36808-dbf7-4bb1-8e82-67aab5f0b9fd_1024x1024.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!abaU!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9f36808-dbf7-4bb1-8e82-67aab5f0b9fd_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!abaU!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9f36808-dbf7-4bb1-8e82-67aab5f0b9fd_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!abaU!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9f36808-dbf7-4bb1-8e82-67aab5f0b9fd_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!abaU!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9f36808-dbf7-4bb1-8e82-67aab5f0b9fd_1024x1024.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!abaU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9f36808-dbf7-4bb1-8e82-67aab5f0b9fd_1024x1024.webp" width="1024" height="1024" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d9f36808-dbf7-4bb1-8e82-67aab5f0b9fd_1024x1024.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:440720,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/webp&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!abaU!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9f36808-dbf7-4bb1-8e82-67aab5f0b9fd_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!abaU!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9f36808-dbf7-4bb1-8e82-67aab5f0b9fd_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!abaU!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9f36808-dbf7-4bb1-8e82-67aab5f0b9fd_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!abaU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9f36808-dbf7-4bb1-8e82-67aab5f0b9fd_1024x1024.webp 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>Cache and buffers in the context of Linux memory management are specific areas <strong>within RAM</strong> that the operating system uses for different purposes. Here's how they work in detail:</p><h3><strong>Cache in Linux</strong></h3><ul><li><p><strong>What it is</strong>:<br>Cache in Linux refers to a portion of RAM that is used to store frequently accessed data (e.g., disk blocks, files, or application data). The kernel dynamically manages this area to speed up future access to the same data.</p></li><li><p><strong>Purpose</strong>:<br>To reduce the need to fetch data repeatedly from slower storage devices (e.g., hard drives or SSDs), improving overall performance.</p></li><li><p><strong>How it Works</strong>:</p><ul><li><p>When a file is read from disk, the kernel keeps a copy of the file's data in the <strong>page cache</strong> (a part of RAM).</p></li><li><p>If the same file or block is accessed again, the kernel serves it from the cache instead of reading it from the disk.</p></li></ul></li><li><p><strong>Dynamic Nature</strong>:<br>The size of the cache is not fixed&#8212;it grows and shrinks based on system demand. For example:</p><ul><li><p>If an application requests more memory, the kernel may shrink the cache to free up space.</p></li><li><p>When the system is idle, unused RAM is often repurposed as cache.</p></li></ul></li><li><p><strong>Types of Cache in RAM</strong>:</p><ul><li><p><strong>Page Cache</strong>: Stores file data.</p></li><li><p><strong>dentry and inode Cache</strong>: Speeds up filesystem operations by caching directory entries and inodes.</p></li></ul></li></ul><div><hr></div><h3><strong>Buffer in Linux</strong></h3><ul><li><p><strong>What it is</strong>:<br>Buffers in Linux are areas of RAM used to temporarily store data being transferred between the operating system and storage devices.</p></li><li><p><strong>Purpose</strong>:<br>To manage the differences in speed between fast processors and slower I/O devices (e.g., disks). Buffers ensure smooth data flow without making the CPU wait.</p></li><li><p><strong>How it Works</strong>:</p><ul><li><p>For <strong>write operations</strong>, data is first written to the buffer in RAM. Later, the kernel flushes this data to the storage device in larger chunks, which is more efficient.</p></li><li><p>For <strong>read operations</strong>, the buffer holds data read from storage, ensuring the CPU has immediate access to it.</p></li></ul></li><li><p><strong>Dynamic Nature</strong>:<br>Like the cache, buffers are also dynamically allocated within RAM based on workload and system requirements.</p></li></ul><div><hr></div><h3><strong>Are Cache and Buffers Physically Separate?</strong></h3><p>No, <strong>cache and buffers are logical allocations within RAM</strong>. They are not special hardware components or reserved physical memory regions. Instead, the kernel uses parts of the available RAM dynamically for these purposes.</p><h3><strong>How Do Cache and Buffers Differ from Hardware Caches?</strong></h3><ul><li><p><strong>Cache in RAM</strong> vs. <strong>CPU Cache</strong>:</p><ul><li><p><strong>CPU Cache</strong> (e.g., L1, L2, L3) is a hardware feature built into the processor, designed to speed up access to frequently used instructions or data.</p></li><li><p><strong>RAM Cache</strong> (Linux page cache) is managed by the operating system and is used for data fetched from storage devices.</p></li></ul></li><li><p><strong>Buffer in RAM</strong> vs. <strong>Device-Specific Buffers</strong>:</p><ul><li><p>Many devices (e.g., hard drives, SSDs, and network cards) have their own hardware buffers to temporarily hold data during transfers.</p></li><li><p>Linux buffers in RAM work at a higher level, coordinating data flow between the operating system and hardware.</p></li></ul></li></ul><div><hr></div><h3>Visualizing Cache and Buffers in RAM</h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Zn9B!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d555a09-e764-4941-8f74-83dce38e81f8_692x277.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Zn9B!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d555a09-e764-4941-8f74-83dce38e81f8_692x277.png 424w, https://substackcdn.com/image/fetch/$s_!Zn9B!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d555a09-e764-4941-8f74-83dce38e81f8_692x277.png 848w, https://substackcdn.com/image/fetch/$s_!Zn9B!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d555a09-e764-4941-8f74-83dce38e81f8_692x277.png 1272w, https://substackcdn.com/image/fetch/$s_!Zn9B!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d555a09-e764-4941-8f74-83dce38e81f8_692x277.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Zn9B!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d555a09-e764-4941-8f74-83dce38e81f8_692x277.png" width="692" height="277" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3d555a09-e764-4941-8f74-83dce38e81f8_692x277.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:277,&quot;width&quot;:692,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:16377,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Zn9B!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d555a09-e764-4941-8f74-83dce38e81f8_692x277.png 424w, https://substackcdn.com/image/fetch/$s_!Zn9B!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d555a09-e764-4941-8f74-83dce38e81f8_692x277.png 848w, https://substackcdn.com/image/fetch/$s_!Zn9B!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d555a09-e764-4941-8f74-83dce38e81f8_692x277.png 1272w, https://substackcdn.com/image/fetch/$s_!Zn9B!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d555a09-e764-4941-8f74-83dce38e81f8_692x277.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3><strong>How Cache and Buffers are Managed by the Kernel</strong></h3><ol><li><p><strong>Dynamic Allocation</strong>:<br>Cache and buffer areas shrink or grow based on system demand. The kernel prioritizes applications over cache and buffers when memory is constrained.</p></li><li><p><strong>Reclaiming Memory</strong>:<br>When applications need more memory, the kernel can:</p><ul><li><p><strong>Drop Cache</strong>: Remove stale or infrequently used cached data.</p></li><li><p><strong>Flush Buffers</strong>: Write buffered data to storage devices to free up RAM.</p></li></ul></li></ol><h3><strong>Summary</strong></h3><ul><li><p><strong>Cache</strong> and <strong>buffers</strong> are logical areas in RAM used to improve I/O performance.</p></li><li><p>They are not physically separate hardware components but are dynamically allocated by the kernel.</p></li><li><p>Cache holds frequently accessed data, while buffers handle temporary I/O data transfers.</p></li><li><p>Their dynamic and transparent management by the Linux kernel ensures efficient memory usage and optimized system performance.</p><p></p></li></ul><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">GOPAKUMAR RAJAPPAN is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Swapping in Linux: Extending Memory with Disk Space]]></title><description><![CDATA[Swapping is a vital mechanism in Linux memory management that helps the system handle memory pressure when physical RAM is insufficient.]]></description><link>https://www.gopakumar-rajappan.com/p/swapping-in-linux-extending-memory</link><guid isPermaLink="false">https://www.gopakumar-rajappan.com/p/swapping-in-linux-extending-memory</guid><dc:creator><![CDATA[GOPAKUMAR RAJAPPAN]]></dc:creator><pubDate>Fri, 29 Nov 2024 21:25:03 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!07Vw!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc14b79c-239f-4688-b8a2-d0f748290d5e_1024x1024.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!07Vw!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc14b79c-239f-4688-b8a2-d0f748290d5e_1024x1024.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!07Vw!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc14b79c-239f-4688-b8a2-d0f748290d5e_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!07Vw!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc14b79c-239f-4688-b8a2-d0f748290d5e_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!07Vw!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc14b79c-239f-4688-b8a2-d0f748290d5e_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!07Vw!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc14b79c-239f-4688-b8a2-d0f748290d5e_1024x1024.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!07Vw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc14b79c-239f-4688-b8a2-d0f748290d5e_1024x1024.webp" width="1024" height="1024" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fc14b79c-239f-4688-b8a2-d0f748290d5e_1024x1024.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:323842,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/webp&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!07Vw!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc14b79c-239f-4688-b8a2-d0f748290d5e_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!07Vw!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc14b79c-239f-4688-b8a2-d0f748290d5e_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!07Vw!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc14b79c-239f-4688-b8a2-d0f748290d5e_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!07Vw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc14b79c-239f-4688-b8a2-d0f748290d5e_1024x1024.webp 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Swapping is a vital mechanism in Linux memory management that helps the system handle memory pressure when physical RAM is insufficient. It involves moving inactive memory pages from RAM to a designated <strong>swap space</strong> on a storage device, allowing active processes to continue functioning smoothly. In this blog, we&#8217;ll explore the concept of swapping, its benefits and drawbacks, and how to monitor and manage it effectively.</p><div><hr></div><h3><strong>What is Swapping?</strong></h3><p>Swapping refers to the process of moving <strong>inactive pages</strong> of memory from RAM to <strong>swap space</strong>, freeing up RAM for active processes. Swap space is typically a portion of a disk (e.g., a swap partition or swap file) reserved for this purpose.</p><div><hr></div><h3><strong>Why is Swapping Needed?</strong></h3><ol><li><p><strong>Memory Overcommitment</strong>:</p><ul><li><p>When the combined memory requirements of all running processes exceed the available physical RAM, swapping allows the system to handle the excess.</p></li></ul></li><li><p><strong>Avoiding Out-of-Memory (OOM) Errors</strong>:</p><ul><li><p>Without swapping, the kernel would need to terminate processes when memory is exhausted.</p></li></ul></li><li><p><strong>Supporting Large Workloads</strong>:</p><ul><li><p>Swapping helps the system accommodate workloads that require more memory than is physically available.</p></li></ul></li></ol><div><hr></div><h3><strong>How Swapping Works</strong></h3><h4><strong>Step 1: Identifying Pages to Swap</strong></h4><ul><li><p>The kernel selects <strong>inactive pages</strong> (pages not recently accessed) to move to swap space.</p></li><li><p>This selection is based on algorithms like <strong>Least Recently Used (LRU)</strong> to minimize performance impact.</p></li></ul><h4><strong>Step 2: Writing Pages to Swap</strong></h4><ul><li><p>The selected pages are compressed (if supported) and written to the swap space.</p></li><li><p>The corresponding physical RAM is freed up for active pages.</p></li></ul><h4><strong>Step 3: Retrieving Pages from Swap</strong></h4><ul><li><p>When a swapped-out page is accessed, the kernel retrieves it from swap space and moves it back to RAM.</p></li><li><p>If RAM is full, another inactive page is swapped out to make room.</p></li></ul><div><hr></div><h3><strong>Benefits of Swapping</strong></h3><ol><li><p><strong>Memory Extension</strong>:</p><ul><li><p>Swap acts as an extension of physical RAM, allowing the system to run larger workloads.</p></li></ul></li><li><p><strong>Improved Stability</strong>:</p><ul><li><p>Prevents OOM errors by ensuring the system can handle memory exhaustion gracefully.</p></li></ul></li><li><p><strong>Enhanced Multitasking</strong>:</p><ul><li><p>Enables more processes to run concurrently by offloading inactive pages.</p></li></ul></li></ol><div><hr></div><h3><strong>Drawbacks of Swapping</strong></h3><ol><li><p><strong>Performance Penalty</strong>:</p><ul><li><p>Disks are significantly slower than RAM, so accessing swapped-out pages can degrade performance.</p></li></ul></li><li><p><strong>Increased Latency</strong>:</p><ul><li><p>Frequent swapping (also called <strong>thrashing</strong>) can cause noticeable delays as the system spends more time moving pages between RAM and disk.</p></li></ul></li><li><p><strong>Wear and Tear</strong>:</p><ul><li><p>On SSDs, excessive swapping can reduce the lifespan of the drive due to write cycles.</p></li></ul></li></ol><div><hr></div><h3><strong>Swap Space Types</strong></h3><ol><li><p><strong>Swap Partition</strong>:</p><ul><li><p>A dedicated partition on a disk reserved for swapping.</p></li><li><p>Example: <code>/dev/sda2</code>.</p></li></ul></li><li><p><strong>Swap File</strong>:</p><ul><li><p>A regular file on the filesystem that serves as swap space.</p></li><li><p>Easier to resize and manage compared to partitions.</p></li></ul></li></ol><h3><strong>Monitoring and Managing Swap</strong></h3><h4><strong>Commands to Monitor Swap</strong></h4><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!hGDs!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76f427bb-c371-46eb-bdf4-f4bf0fb7aa14_925x227.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!hGDs!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76f427bb-c371-46eb-bdf4-f4bf0fb7aa14_925x227.png 424w, https://substackcdn.com/image/fetch/$s_!hGDs!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76f427bb-c371-46eb-bdf4-f4bf0fb7aa14_925x227.png 848w, https://substackcdn.com/image/fetch/$s_!hGDs!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76f427bb-c371-46eb-bdf4-f4bf0fb7aa14_925x227.png 1272w, https://substackcdn.com/image/fetch/$s_!hGDs!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76f427bb-c371-46eb-bdf4-f4bf0fb7aa14_925x227.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!hGDs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76f427bb-c371-46eb-bdf4-f4bf0fb7aa14_925x227.png" width="925" height="227" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/76f427bb-c371-46eb-bdf4-f4bf0fb7aa14_925x227.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:227,&quot;width&quot;:925,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:21974,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!hGDs!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76f427bb-c371-46eb-bdf4-f4bf0fb7aa14_925x227.png 424w, https://substackcdn.com/image/fetch/$s_!hGDs!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76f427bb-c371-46eb-bdf4-f4bf0fb7aa14_925x227.png 848w, https://substackcdn.com/image/fetch/$s_!hGDs!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76f427bb-c371-46eb-bdf4-f4bf0fb7aa14_925x227.png 1272w, https://substackcdn.com/image/fetch/$s_!hGDs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76f427bb-c371-46eb-bdf4-f4bf0fb7aa14_925x227.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><h4><strong>Adjusting Swap Behavior</strong></h4><ol><li><p><strong>Swappiness</strong>:</p><ul><li><p>Controls how aggressively the kernel uses swap space.</p></li><li><p>Value ranges from <code>0</code> (minimize swapping) to <code>100</code> (maximize swapping).</p></li></ul></li></ol><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!4QMi!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46de2c17-1f3d-440e-88ea-c865ea1b3554_617x248.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!4QMi!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46de2c17-1f3d-440e-88ea-c865ea1b3554_617x248.png 424w, https://substackcdn.com/image/fetch/$s_!4QMi!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46de2c17-1f3d-440e-88ea-c865ea1b3554_617x248.png 848w, https://substackcdn.com/image/fetch/$s_!4QMi!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46de2c17-1f3d-440e-88ea-c865ea1b3554_617x248.png 1272w, https://substackcdn.com/image/fetch/$s_!4QMi!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46de2c17-1f3d-440e-88ea-c865ea1b3554_617x248.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!4QMi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46de2c17-1f3d-440e-88ea-c865ea1b3554_617x248.png" width="617" height="248" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/46de2c17-1f3d-440e-88ea-c865ea1b3554_617x248.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:248,&quot;width&quot;:617,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:15270,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!4QMi!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46de2c17-1f3d-440e-88ea-c865ea1b3554_617x248.png 424w, https://substackcdn.com/image/fetch/$s_!4QMi!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46de2c17-1f3d-440e-88ea-c865ea1b3554_617x248.png 848w, https://substackcdn.com/image/fetch/$s_!4QMi!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46de2c17-1f3d-440e-88ea-c865ea1b3554_617x248.png 1272w, https://substackcdn.com/image/fetch/$s_!4QMi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46de2c17-1f3d-440e-88ea-c865ea1b3554_617x248.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><ol start="2"><li><p><strong>Adding Swap Space</strong>:</p><ul><li><p><strong>Create a Swap File</strong>:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ZGNK!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfb4b3f7-0fa4-46d1-84fa-71daad5e958e_345x133.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ZGNK!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfb4b3f7-0fa4-46d1-84fa-71daad5e958e_345x133.png 424w, https://substackcdn.com/image/fetch/$s_!ZGNK!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfb4b3f7-0fa4-46d1-84fa-71daad5e958e_345x133.png 848w, https://substackcdn.com/image/fetch/$s_!ZGNK!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfb4b3f7-0fa4-46d1-84fa-71daad5e958e_345x133.png 1272w, https://substackcdn.com/image/fetch/$s_!ZGNK!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfb4b3f7-0fa4-46d1-84fa-71daad5e958e_345x133.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ZGNK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfb4b3f7-0fa4-46d1-84fa-71daad5e958e_345x133.png" width="345" height="133" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/dfb4b3f7-0fa4-46d1-84fa-71daad5e958e_345x133.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:133,&quot;width&quot;:345,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:6652,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ZGNK!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfb4b3f7-0fa4-46d1-84fa-71daad5e958e_345x133.png 424w, https://substackcdn.com/image/fetch/$s_!ZGNK!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfb4b3f7-0fa4-46d1-84fa-71daad5e958e_345x133.png 848w, https://substackcdn.com/image/fetch/$s_!ZGNK!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfb4b3f7-0fa4-46d1-84fa-71daad5e958e_345x133.png 1272w, https://substackcdn.com/image/fetch/$s_!ZGNK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfb4b3f7-0fa4-46d1-84fa-71daad5e958e_345x133.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p><strong>Make it Persistent</strong>: Add the following line to <code>/etc/fstab</code>:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!XSGu!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b4d3ab0-2bea-4242-9d13-3fad86ba9486_763x50.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!XSGu!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b4d3ab0-2bea-4242-9d13-3fad86ba9486_763x50.png 424w, https://substackcdn.com/image/fetch/$s_!XSGu!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b4d3ab0-2bea-4242-9d13-3fad86ba9486_763x50.png 848w, https://substackcdn.com/image/fetch/$s_!XSGu!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b4d3ab0-2bea-4242-9d13-3fad86ba9486_763x50.png 1272w, https://substackcdn.com/image/fetch/$s_!XSGu!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b4d3ab0-2bea-4242-9d13-3fad86ba9486_763x50.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!XSGu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b4d3ab0-2bea-4242-9d13-3fad86ba9486_763x50.png" width="763" height="50" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9b4d3ab0-2bea-4242-9d13-3fad86ba9486_763x50.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:50,&quot;width&quot;:763,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2699,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!XSGu!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b4d3ab0-2bea-4242-9d13-3fad86ba9486_763x50.png 424w, https://substackcdn.com/image/fetch/$s_!XSGu!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b4d3ab0-2bea-4242-9d13-3fad86ba9486_763x50.png 848w, https://substackcdn.com/image/fetch/$s_!XSGu!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b4d3ab0-2bea-4242-9d13-3fad86ba9486_763x50.png 1272w, https://substackcdn.com/image/fetch/$s_!XSGu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b4d3ab0-2bea-4242-9d13-3fad86ba9486_763x50.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div></li></ul></li><li><p><strong>Removing Swap Space</strong>:</p><ul><li><p>Disable the swap file:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!DBnZ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8631e1c-518f-4d4f-8a4b-205d046edd2c_761x48.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!DBnZ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8631e1c-518f-4d4f-8a4b-205d046edd2c_761x48.png 424w, https://substackcdn.com/image/fetch/$s_!DBnZ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8631e1c-518f-4d4f-8a4b-205d046edd2c_761x48.png 848w, https://substackcdn.com/image/fetch/$s_!DBnZ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8631e1c-518f-4d4f-8a4b-205d046edd2c_761x48.png 1272w, https://substackcdn.com/image/fetch/$s_!DBnZ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8631e1c-518f-4d4f-8a4b-205d046edd2c_761x48.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!DBnZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8631e1c-518f-4d4f-8a4b-205d046edd2c_761x48.png" width="761" height="48" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c8631e1c-518f-4d4f-8a4b-205d046edd2c_761x48.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:48,&quot;width&quot;:761,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2332,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!DBnZ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8631e1c-518f-4d4f-8a4b-205d046edd2c_761x48.png 424w, https://substackcdn.com/image/fetch/$s_!DBnZ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8631e1c-518f-4d4f-8a4b-205d046edd2c_761x48.png 848w, https://substackcdn.com/image/fetch/$s_!DBnZ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8631e1c-518f-4d4f-8a4b-205d046edd2c_761x48.png 1272w, https://substackcdn.com/image/fetch/$s_!DBnZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8631e1c-518f-4d4f-8a4b-205d046edd2c_761x48.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div></li></ul></li></ol><h3><strong>Tips for Effective Swap Management</strong></h3><h4><strong>For Developers</strong>:</h4><ol><li><p><strong>Optimize Memory Usage</strong>:</p><ul><li><p>Avoid excessive memory consumption to minimize swapping.</p></li></ul></li><li><p><strong>Handle Latency Gracefully</strong>:</p><ul><li><p>Design applications to tolerate delays caused by swapping.</p></li></ul></li></ol><h4><strong>For System Administrators</strong>:</h4><ol><li><p><strong>Monitor Swap Usage</strong>:</p><ul><li><p>Use tools like <code>htop</code> or <code>free</code> to detect heavy swapping.</p></li></ul></li><li><p><strong>Optimize Swappiness</strong>:</p><ul><li><p>Adjust swappiness based on workload requirements (e.g., databases may prefer minimal swapping).</p></li></ul></li><li><p><strong>Use SSDs for Swap</strong>:</p><ul><li><p>If possible, place swap space on SSDs for faster access.</p></li></ul></li></ol><div><hr></div><h3><strong>Conclusion</strong></h3><p>Swapping is a critical feature of Linux memory management that extends the system&#8217;s memory capabilities beyond physical RAM. While it provides stability and flexibility, it comes with trade-offs in performance. By understanding how swapping works and monitoring its usage, you can ensure that your system remains responsive and efficient under memory pressure.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">GOPAKUMAR RAJAPPAN is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Paging in Linux: Breaking Memory into Manageable Pieces]]></title><description><![CDATA[Paging is the foundation of Linux memory management, enabling efficient use of RAM and providing the flexibility of virtual memory.]]></description><link>https://www.gopakumar-rajappan.com/p/paging-in-linux-breaking-memory-into</link><guid isPermaLink="false">https://www.gopakumar-rajappan.com/p/paging-in-linux-breaking-memory-into</guid><dc:creator><![CDATA[GOPAKUMAR RAJAPPAN]]></dc:creator><pubDate>Fri, 29 Nov 2024 21:12:26 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!U7FW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b6231c0-3160-4f4e-82fc-92c8b4f6c20c_1024x1024.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!U7FW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b6231c0-3160-4f4e-82fc-92c8b4f6c20c_1024x1024.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!U7FW!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b6231c0-3160-4f4e-82fc-92c8b4f6c20c_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!U7FW!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b6231c0-3160-4f4e-82fc-92c8b4f6c20c_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!U7FW!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b6231c0-3160-4f4e-82fc-92c8b4f6c20c_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!U7FW!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b6231c0-3160-4f4e-82fc-92c8b4f6c20c_1024x1024.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!U7FW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b6231c0-3160-4f4e-82fc-92c8b4f6c20c_1024x1024.webp" width="1024" height="1024" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5b6231c0-3160-4f4e-82fc-92c8b4f6c20c_1024x1024.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:486686,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/webp&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!U7FW!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b6231c0-3160-4f4e-82fc-92c8b4f6c20c_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!U7FW!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b6231c0-3160-4f4e-82fc-92c8b4f6c20c_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!U7FW!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b6231c0-3160-4f4e-82fc-92c8b4f6c20c_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!U7FW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b6231c0-3160-4f4e-82fc-92c8b4f6c20c_1024x1024.webp 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Paging is the foundation of Linux memory management, enabling efficient use of RAM and providing the flexibility of virtual memory. It works by dividing memory into fixed-size blocks, simplifying allocation, and ensuring process isolation. Let&#8217;s break this down in simple, clear terms with an easy-to-follow example.</p><div><hr></div><h3><strong>What is Paging?</strong></h3><ul><li><p>Paging divides memory into <strong>fixed-size blocks</strong> for easier management:</p><ul><li><p><strong>Virtual Pages</strong>: Blocks of virtual memory (e.g., 4 KB each).</p></li><li><p><strong>Physical Frames</strong>: Blocks of physical RAM corresponding to virtual pages.</p></li></ul></li><li><p>The kernel uses <strong>page tables</strong> to map virtual pages (used by processes) to physical frames (actual locations in RAM).</p></li></ul><div><hr></div><h3><strong>Why Paging is Needed</strong></h3><ol><li><p><strong>Process Isolation</strong>:</p><ul><li><p>Every process gets its own virtual memory space, so they can&#8217;t interfere with each other.</p></li></ul></li><li><p><strong>Efficient Memory Use</strong>:</p><ul><li><p>Memory is allocated in fixed-sized chunks, avoiding fragmentation.</p></li></ul></li><li><p><strong>Handling Larger Memory Needs</strong>:</p><ul><li><p>Processes can use more memory than what&#8217;s physically available by using <strong>swap space</strong>.</p></li></ul></li></ol><div><hr></div><h3><strong>How Paging Works: A Simple Breakdown</strong></h3><ol><li><p><strong>Virtual and Physical Memory Divided into Pages and Frames</strong>:</p><ul><li><p>Imagine virtual memory as a book, where each page represents a block of memory.</p></li><li><p>Physical RAM is like a smaller notebook, also divided into pages (frames).</p></li><li><p>Each virtual page must be placed into a physical frame when the process accesses it.</p></li></ul></li><li><p><strong>Mapping Virtual Pages to Physical Frames</strong>:</p><ul><li><p>The kernel maintains a <strong>page table</strong> for each process, which acts as a map:</p><ul><li><p><strong>Virtual Page Number</strong> (VPN): The page in the process's virtual memory.</p></li><li><p><strong>Physical Frame Number (PFN)</strong>: The corresponding frame in physical RAM.</p></li></ul></li><li><p>Example:<br>Virtual page 3 might be mapped to physical frame 1.</p></li></ul></li><li><p><strong>Address Translation</strong>:</p><ul><li><p>When a process accesses an address in virtual memory, the <strong>Memory Management Unit (MMU)</strong> translates it into a physical address using the page table.</p></li></ul></li></ol><div><hr></div><h3><strong>Example: Paging in Action</strong></h3><h4><strong>Scenario</strong>:</h4><p>A process wants to access data at <strong>virtual address 0x1234</strong>.</p><h4><strong>Steps</strong>:</h4><ol><li><p><strong>Divide the Address</strong>:</p><ul><li><p>The virtual address (e.g., <strong>0x1234</strong>) is divided into two parts:</p><ul><li><p><strong>Virtual Page Number (VPN)</strong>: Identifies the virtual page (e.g., page 1).</p></li><li><p><strong>Page Offset</strong>: Identifies the location within the page (e.g., offset 0x234).</p></li></ul></li></ul></li><li><p><strong>Page Table Lookup</strong>:</p><ul><li><p>The MMU checks the process's page table to find where virtual page 1 is stored:</p><ul><li><p>Virtual page 1 is mapped to <strong>physical frame 3</strong>.</p></li></ul></li></ul></li><li><p><strong>Translate to Physical Address</strong>:</p><ul><li><p>The MMU combines:</p><ul><li><p>The physical frame number (e.g., frame 3).</p></li><li><p>The page offset (e.g., 0x234).</p></li></ul></li><li><p>The physical address becomes <strong>frame 3 + offset 0x234</strong>.</p></li></ul></li></ol><h4><strong>What Happens Next?</strong></h4><ul><li><p>If the data is in RAM, it is accessed directly.</p></li><li><p>If the page is not in RAM (a <strong>page fault</strong>), the kernel retrieves it from swap or loads it from disk into a free physical frame.</p></li></ul><div><hr></div><h3><strong>Page Faults: When Paging Goes Beyond RAM</strong></h3><h4><strong>What is a Page Fault?</strong></h4><p>A page fault occurs when the process tries to access a page that is not currently in physical memory.</p><h4><strong>How the Kernel Handles Page Faults</strong>:</h4><ol><li><p>The kernel identifies the required page.</p></li><li><p>If the page is in swap space:</p><ul><li><p>It is loaded back into a free frame in RAM.</p></li></ul></li><li><p>If the page is not in swap:</p><ul><li><p>The kernel loads it from the original file (e.g., an executable or data file).</p></li></ul></li></ol><h4><strong>Example of Page Fault</strong>:</h4><ul><li><p>A program accesses a large file that exceeds the size of RAM:</p><ul><li><p>Initially, only parts of the file are loaded into memory.</p></li><li><p>When the program accesses an unmapped part, a page fault occurs.</p></li><li><p>The kernel retrieves the missing page from disk and maps it to RAM.</p></li></ul></li></ul><div><hr></div><h3><strong>How Pages and Frames Help</strong></h3><ol><li><p><strong>Efficient Allocation</strong>:</p><ul><li><p>Memory is allocated in uniform page sizes, reducing fragmentation.</p></li></ul></li><li><p><strong>Flexible Use of Memory</strong>:</p><ul><li><p>Pages can be moved in and out of RAM dynamically, enabling multitasking.</p></li></ul></li><li><p><strong>Isolation</strong>:</p><ul><li><p>Each process only accesses its own virtual pages, even if multiple processes share the same physical memory.</p></li></ul></li></ol><div><hr></div><h3><strong>Key Tools for Monitoring Paging in Linux</strong></h3><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!iuu2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73da47a4-0cbc-4b6c-8c2b-aad9596134fe_927x183.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!iuu2!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73da47a4-0cbc-4b6c-8c2b-aad9596134fe_927x183.png 424w, https://substackcdn.com/image/fetch/$s_!iuu2!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73da47a4-0cbc-4b6c-8c2b-aad9596134fe_927x183.png 848w, https://substackcdn.com/image/fetch/$s_!iuu2!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73da47a4-0cbc-4b6c-8c2b-aad9596134fe_927x183.png 1272w, https://substackcdn.com/image/fetch/$s_!iuu2!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73da47a4-0cbc-4b6c-8c2b-aad9596134fe_927x183.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!iuu2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73da47a4-0cbc-4b6c-8c2b-aad9596134fe_927x183.png" width="927" height="183" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/73da47a4-0cbc-4b6c-8c2b-aad9596134fe_927x183.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:183,&quot;width&quot;:927,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:17657,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!iuu2!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73da47a4-0cbc-4b6c-8c2b-aad9596134fe_927x183.png 424w, https://substackcdn.com/image/fetch/$s_!iuu2!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73da47a4-0cbc-4b6c-8c2b-aad9596134fe_927x183.png 848w, https://substackcdn.com/image/fetch/$s_!iuu2!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73da47a4-0cbc-4b6c-8c2b-aad9596134fe_927x183.png 1272w, https://substackcdn.com/image/fetch/$s_!iuu2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73da47a4-0cbc-4b6c-8c2b-aad9596134fe_927x183.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><h3><strong>Why Developers and Administrators Should Care</strong></h3><h4><strong>For Developers</strong>:</h4><ol><li><p>Optimize memory usage by understanding how paging affects performance.</p></li><li><p>Minimize page faults in large applications to avoid costly disk I/O.</p></li></ol><h4><strong>For Administrators</strong>:</h4><ol><li><p>Monitor paging activity to detect memory bottlenecks.</p></li><li><p>Manage swap space effectively to prevent performance degradation.</p></li></ol><div><hr></div><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">GOPAKUMAR RAJAPPAN is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Virtual Memory - The Illusion of Unlimited RAM]]></title><description><![CDATA[Virtual memory is a technique that allows the operating system to make each process believe it has access to a large, contiguous block of memory, regardless of the actual physical RAM available.]]></description><link>https://www.gopakumar-rajappan.com/p/virtual-memory-the-illusion-of-unlimited</link><guid isPermaLink="false">https://www.gopakumar-rajappan.com/p/virtual-memory-the-illusion-of-unlimited</guid><dc:creator><![CDATA[GOPAKUMAR RAJAPPAN]]></dc:creator><pubDate>Fri, 29 Nov 2024 20:43:29 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!AKaL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25987346-0d10-45d1-8b6c-a0acbd8157ae_1024x1024.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!AKaL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25987346-0d10-45d1-8b6c-a0acbd8157ae_1024x1024.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!AKaL!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25987346-0d10-45d1-8b6c-a0acbd8157ae_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!AKaL!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25987346-0d10-45d1-8b6c-a0acbd8157ae_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!AKaL!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25987346-0d10-45d1-8b6c-a0acbd8157ae_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!AKaL!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25987346-0d10-45d1-8b6c-a0acbd8157ae_1024x1024.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!AKaL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25987346-0d10-45d1-8b6c-a0acbd8157ae_1024x1024.webp" width="1024" height="1024" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/25987346-0d10-45d1-8b6c-a0acbd8157ae_1024x1024.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:493932,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/webp&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!AKaL!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25987346-0d10-45d1-8b6c-a0acbd8157ae_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!AKaL!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25987346-0d10-45d1-8b6c-a0acbd8157ae_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!AKaL!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25987346-0d10-45d1-8b6c-a0acbd8157ae_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!AKaL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25987346-0d10-45d1-8b6c-a0acbd8157ae_1024x1024.webp 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>Virtual memory is a technique that allows the operating system to make each process believe it has access to a large, contiguous block of memory, regardless of the actual physical RAM available. This abstraction simplifies programming and ensures better memory utilization.</p><h4><strong>How Virtual Memory Works</strong></h4><ol><li><p><strong>Virtual Addresses</strong>:</p><ul><li><p>Every process generates <strong>virtual addresses</strong>, which the kernel maps to <strong>physical addresses</strong> (actual locations in RAM or storage) using page tables.</p></li></ul></li><li><p><strong>Memory Isolation</strong>:</p><ul><li><p>Each process gets its own isolated virtual address space, preventing interference with other processes.</p></li></ul></li><li><p><strong>Address Translation</strong>:</p><ul><li><p>The <strong>Memory Management Unit (MMU)</strong> in the CPU translates virtual addresses into physical addresses during program execution.</p></li></ul></li></ol><h4><strong>Benefits of Virtual Memory</strong></h4><ul><li><p>Memory sharing: Multiple processes can share the same physical memory while maintaining separate virtual spaces.</p></li><li><p>Memory over commitment: Processes can request more memory than is physically available, relying on <strong>swapping</strong>.</p><p></p></li></ul><h4><strong>Example</strong>:</h4><p>Imagine a computer with 4 GB of RAM. If three programs, each requesting 3 GB, run simultaneously.</p><h4><strong>Step 1: Initial Memory Allocation</strong></h4><ul><li><p>Each of the three processes requests <strong>3GB</strong> of memory.</p></li><li><p>Virtual memory is allocated as follows:</p><ul><li><p><strong>Process 1</strong>:   3GB virtual memory.</p></li><li><p><strong>Process 2</strong>:   3GB virtual memory.</p></li><li><p><strong>Process 3</strong>:   3GB virtual memory.</p></li></ul></li></ul><h4><strong>Step 2: Physical RAM Usage</strong></h4><ul><li><p>Physical RAM (4GB) is shared dynamically between the processes.</p></li><li><p>The kernel loads the <strong>active parts</strong> of each process into RAM. For example:</p><ul><li><p><strong>Process 1</strong>: 1.5GB in RAM (active parts).</p></li><li><p><strong>Process 2</strong>: 1.5GB in RAM (active parts).</p></li><li><p><strong>Process 3</strong>: 1GB in RAM (active parts).</p></li></ul></li><li><p>Total: 4GB of physical RAM is used.</p></li></ul><h4><strong>Step 3: Swapping</strong></h4><ul><li><p>The <strong>inactive parts</strong> of the processes (e.g., data not being immediately accessed) are moved to swap space.</p></li><li><p>Example:</p><ul><li><p><strong>Process 1</strong>: 1.5GB in swap.</p></li><li><p><strong>Process 2</strong>: 1.5GB in swap.</p></li><li><p><strong>Process 3</strong>: 2GB in swap.</p></li></ul></li><li><p>Total: 6GB of swap space is used.</p></li></ul><h4><strong>Step 4: Execution</strong></h4><ul><li><p>The kernel dynamically moves data between RAM and swap space as needed.</p></li><li><p>If <strong>Process 2</strong> suddenly becomes more active, its required pages are brought back into RAM, while less-used pages from <strong>Process 1</strong> or <strong>Process 3</strong> are moved to swap.</p></li></ul><p></p><h3><strong>Key Features of Virtual Memory</strong></h3><ol><li><p><strong>Memory Overcommitment</strong>:</p><ul><li><p>Virtual memory allows processes to collectively request more memory than the available physical RAM.</p></li></ul></li><li><p><strong>Isolation</strong>:</p><ul><li><p>Each process operates in its own virtual address space, so processes cannot interfere with each other&#8217;s memory.</p></li></ul></li><li><p><strong>Dynamic Management</strong>:</p><ul><li><p>The kernel moves data between RAM and swap space as needed, prioritizing active memory.</p></li></ul></li></ol><h3><strong>Monitoring Virtual Memory in Linux</strong></h3><p>Use these commands to monitor how virtual memory is used:</p><ol><li><p><code>free -h</code>:</p><p>Shows the total, used, and available memory, including swap.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ImcQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ca20412-1572-4e7b-82fc-5113d331ad9b_812x51.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ImcQ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ca20412-1572-4e7b-82fc-5113d331ad9b_812x51.png 424w, https://substackcdn.com/image/fetch/$s_!ImcQ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ca20412-1572-4e7b-82fc-5113d331ad9b_812x51.png 848w, https://substackcdn.com/image/fetch/$s_!ImcQ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ca20412-1572-4e7b-82fc-5113d331ad9b_812x51.png 1272w, https://substackcdn.com/image/fetch/$s_!ImcQ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ca20412-1572-4e7b-82fc-5113d331ad9b_812x51.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ImcQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ca20412-1572-4e7b-82fc-5113d331ad9b_812x51.png" width="812" height="51" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9ca20412-1572-4e7b-82fc-5113d331ad9b_812x51.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:51,&quot;width&quot;:812,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1378,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ImcQ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ca20412-1572-4e7b-82fc-5113d331ad9b_812x51.png 424w, https://substackcdn.com/image/fetch/$s_!ImcQ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ca20412-1572-4e7b-82fc-5113d331ad9b_812x51.png 848w, https://substackcdn.com/image/fetch/$s_!ImcQ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ca20412-1572-4e7b-82fc-5113d331ad9b_812x51.png 1272w, https://substackcdn.com/image/fetch/$s_!ImcQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ca20412-1572-4e7b-82fc-5113d331ad9b_812x51.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!G0Wt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F804db52d-6bd8-4098-8959-c83d67fde13a_818x107.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!G0Wt!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F804db52d-6bd8-4098-8959-c83d67fde13a_818x107.png 424w, https://substackcdn.com/image/fetch/$s_!G0Wt!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F804db52d-6bd8-4098-8959-c83d67fde13a_818x107.png 848w, https://substackcdn.com/image/fetch/$s_!G0Wt!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F804db52d-6bd8-4098-8959-c83d67fde13a_818x107.png 1272w, https://substackcdn.com/image/fetch/$s_!G0Wt!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F804db52d-6bd8-4098-8959-c83d67fde13a_818x107.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!G0Wt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F804db52d-6bd8-4098-8959-c83d67fde13a_818x107.png" width="818" height="107" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/804db52d-6bd8-4098-8959-c83d67fde13a_818x107.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:107,&quot;width&quot;:818,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:8089,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!G0Wt!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F804db52d-6bd8-4098-8959-c83d67fde13a_818x107.png 424w, https://substackcdn.com/image/fetch/$s_!G0Wt!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F804db52d-6bd8-4098-8959-c83d67fde13a_818x107.png 848w, https://substackcdn.com/image/fetch/$s_!G0Wt!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F804db52d-6bd8-4098-8959-c83d67fde13a_818x107.png 1272w, https://substackcdn.com/image/fetch/$s_!G0Wt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F804db52d-6bd8-4098-8959-c83d67fde13a_818x107.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p><code>Mem:</code> Shows the physical RAM usage.</p><p><code>Swap:</code> Shows the swap space usage.</p></li><li><p><code>vmstat</code>:</p><ul><li><p>Displays memory and swap activity</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!xf52!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08c8e342-2db0-4e37-8bde-02c051f66547_813x30.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!xf52!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08c8e342-2db0-4e37-8bde-02c051f66547_813x30.png 424w, https://substackcdn.com/image/fetch/$s_!xf52!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08c8e342-2db0-4e37-8bde-02c051f66547_813x30.png 848w, https://substackcdn.com/image/fetch/$s_!xf52!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08c8e342-2db0-4e37-8bde-02c051f66547_813x30.png 1272w, https://substackcdn.com/image/fetch/$s_!xf52!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08c8e342-2db0-4e37-8bde-02c051f66547_813x30.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!xf52!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08c8e342-2db0-4e37-8bde-02c051f66547_813x30.png" width="813" height="30" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/08c8e342-2db0-4e37-8bde-02c051f66547_813x30.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:30,&quot;width&quot;:813,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1308,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!xf52!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08c8e342-2db0-4e37-8bde-02c051f66547_813x30.png 424w, https://substackcdn.com/image/fetch/$s_!xf52!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08c8e342-2db0-4e37-8bde-02c051f66547_813x30.png 848w, https://substackcdn.com/image/fetch/$s_!xf52!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08c8e342-2db0-4e37-8bde-02c051f66547_813x30.png 1272w, https://substackcdn.com/image/fetch/$s_!xf52!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08c8e342-2db0-4e37-8bde-02c051f66547_813x30.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div></li></ul><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ixhr!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b3ea9c2-7def-4068-9b30-35dc75e9a8d7_803x92.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ixhr!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b3ea9c2-7def-4068-9b30-35dc75e9a8d7_803x92.png 424w, https://substackcdn.com/image/fetch/$s_!ixhr!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b3ea9c2-7def-4068-9b30-35dc75e9a8d7_803x92.png 848w, https://substackcdn.com/image/fetch/$s_!ixhr!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b3ea9c2-7def-4068-9b30-35dc75e9a8d7_803x92.png 1272w, https://substackcdn.com/image/fetch/$s_!ixhr!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b3ea9c2-7def-4068-9b30-35dc75e9a8d7_803x92.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ixhr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b3ea9c2-7def-4068-9b30-35dc75e9a8d7_803x92.png" width="642" height="73.55417185554172" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9b3ea9c2-7def-4068-9b30-35dc75e9a8d7_803x92.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:92,&quot;width&quot;:803,&quot;resizeWidth&quot;:642,&quot;bytes&quot;:8651,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ixhr!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b3ea9c2-7def-4068-9b30-35dc75e9a8d7_803x92.png 424w, https://substackcdn.com/image/fetch/$s_!ixhr!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b3ea9c2-7def-4068-9b30-35dc75e9a8d7_803x92.png 848w, https://substackcdn.com/image/fetch/$s_!ixhr!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b3ea9c2-7def-4068-9b30-35dc75e9a8d7_803x92.png 1272w, https://substackcdn.com/image/fetch/$s_!ixhr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b3ea9c2-7def-4068-9b30-35dc75e9a8d7_803x92.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div></li></ol><ul><li><p><code>swpd</code>: Amount of memory swapped out.</p></li><li><p><code>si</code> and <code>so</code>: Swap-in and swap-out activity.</p></li></ul><h3><strong>Conclusion</strong></h3><p>Virtual memory is a foundational concept that allows Linux to provide each process with its own large memory space, even if physical RAM is limited. By dynamically managing the active and inactive parts of processes in RAM and swap space, the kernel ensures smooth multitasking and efficient resource utilization.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">GOPAKUMAR RAJAPPAN is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Process Scheduling in Linux]]></title><description><![CDATA[When multiple processes and threads are running on a Linux system, the kernel must decide which one gets to use the CPU and for how long.]]></description><link>https://www.gopakumar-rajappan.com/p/process-scheduling-in-linux</link><guid isPermaLink="false">https://www.gopakumar-rajappan.com/p/process-scheduling-in-linux</guid><dc:creator><![CDATA[GOPAKUMAR RAJAPPAN]]></dc:creator><pubDate>Fri, 29 Nov 2024 08:17:38 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!sybr!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0c1322b-887f-4db0-ab95-eb4c2c79e4f4_1024x1024.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!sybr!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0c1322b-887f-4db0-ab95-eb4c2c79e4f4_1024x1024.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!sybr!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0c1322b-887f-4db0-ab95-eb4c2c79e4f4_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!sybr!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0c1322b-887f-4db0-ab95-eb4c2c79e4f4_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!sybr!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0c1322b-887f-4db0-ab95-eb4c2c79e4f4_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!sybr!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0c1322b-887f-4db0-ab95-eb4c2c79e4f4_1024x1024.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!sybr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0c1322b-887f-4db0-ab95-eb4c2c79e4f4_1024x1024.webp" width="1024" height="1024" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e0c1322b-887f-4db0-ab95-eb4c2c79e4f4_1024x1024.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:377592,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/webp&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!sybr!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0c1322b-887f-4db0-ab95-eb4c2c79e4f4_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!sybr!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0c1322b-887f-4db0-ab95-eb4c2c79e4f4_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!sybr!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0c1322b-887f-4db0-ab95-eb4c2c79e4f4_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!sybr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0c1322b-887f-4db0-ab95-eb4c2c79e4f4_1024x1024.webp 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>When multiple processes and threads are running on a Linux system, the kernel must decide which one gets to use the CPU and for how long. This decision-making mechanism, known as <strong>process scheduling</strong>, ensures fairness, efficiency, and responsiveness in multitasking environments. In this blog, we&#8217;ll dive into the basics of process scheduling, explore the Linux scheduler, and provide simple examples to understand the concepts.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">GOPAKUMAR RAJAPPAN is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p><h3><strong>What is Process Scheduling?</strong></h3><p><strong>Process scheduling</strong> is the method by which the Linux kernel decides the order in which processes or threads execute. Since the CPU can only execute one task per core at a time, scheduling is crucial for providing the illusion of simultaneous execution (multitasking).</p><div><hr></div><h3><strong>Goals of Process Scheduling</strong></h3><ol><li><p><strong>Fairness</strong>: Ensure all processes get CPU time.</p></li><li><p><strong>Efficiency</strong>: Keep the CPU busy and maximize system performance.</p></li><li><p><strong>Responsiveness</strong>: Minimize latency for interactive processes (e.g., user inputs).</p></li><li><p><strong>Throughput</strong>: Maximize the number of tasks completed in a given period.</p></li><li><p><strong>Real-Time Guarantees</strong>: Provide strict timing guarantees for real-time tasks.</p></li></ol><div><hr></div><h3><strong>Types of Scheduling in Linux</strong></h3><p>Linux supports two main categories of scheduling:</p><h4><strong>1. Preemptive Scheduling</strong></h4><ul><li><p>The currently running process can be interrupted (preempted) if a higher-priority process becomes ready to execute.</p></li><li><p>Ensures that important tasks (e.g., real-time or interactive tasks) don&#8217;t have to wait for lower-priority tasks to complete.</p></li></ul><h4><strong>2. Non-Preemptive Scheduling</strong></h4><ul><li><p>A process runs until it voluntarily relinquishes the CPU (e.g., via I/O operations) or terminates.</p></li><li><p>Less common in modern systems due to its inefficiency for multi-user environments.</p></li></ul><div><hr></div><h3><strong>How the Linux Scheduler Works</strong></h3><p>The <strong>Completely Fair Scheduler (CFS)</strong> is the default scheduler in Linux. It is designed to provide fairness and scalability for most workloads.</p><h4><strong>Key Concepts of the CFS</strong></h4><ol><li><p><strong>Fairness</strong>:</p><ul><li><p>Each process is allocated a proportion of the CPU based on its priority and weight.</p></li><li><p>The scheduler tries to ensure that all processes get an equal amount of CPU time unless priority dictates otherwise.</p></li></ul></li><li><p><strong>Time Slices</strong>:</p><ul><li><p>A <strong>time slice</strong> is the maximum amount of time a process is allowed to run on the CPU before being preempted.</p></li><li><p>Time slices are dynamically calculated based on process priority and system load.</p></li></ul></li><li><p><strong>Run Queue</strong>:</p><ul><li><p>The scheduler maintains a <strong>Run Queue</strong>, which is a list of all processes in the <strong>Runnable</strong> state.</p></li><li><p>The queue is organized as a red-black tree (a type of balanced binary tree) to quickly select the process with the smallest runtime.</p></li></ul></li></ol><div><hr></div><h3><strong>Scheduling Policies</strong></h3><p>Linux provides several scheduling policies, each designed for specific use cases:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!9Y8z!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe684b411-e83b-4ac5-9409-1b4e7942628d_928x417.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!9Y8z!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe684b411-e83b-4ac5-9409-1b4e7942628d_928x417.png 424w, https://substackcdn.com/image/fetch/$s_!9Y8z!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe684b411-e83b-4ac5-9409-1b4e7942628d_928x417.png 848w, https://substackcdn.com/image/fetch/$s_!9Y8z!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe684b411-e83b-4ac5-9409-1b4e7942628d_928x417.png 1272w, https://substackcdn.com/image/fetch/$s_!9Y8z!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe684b411-e83b-4ac5-9409-1b4e7942628d_928x417.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!9Y8z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe684b411-e83b-4ac5-9409-1b4e7942628d_928x417.png" width="928" height="417" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e684b411-e83b-4ac5-9409-1b4e7942628d_928x417.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:417,&quot;width&quot;:928,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:45384,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!9Y8z!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe684b411-e83b-4ac5-9409-1b4e7942628d_928x417.png 424w, https://substackcdn.com/image/fetch/$s_!9Y8z!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe684b411-e83b-4ac5-9409-1b4e7942628d_928x417.png 848w, https://substackcdn.com/image/fetch/$s_!9Y8z!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe684b411-e83b-4ac5-9409-1b4e7942628d_928x417.png 1272w, https://substackcdn.com/image/fetch/$s_!9Y8z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe684b411-e83b-4ac5-9409-1b4e7942628d_928x417.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3><strong>Understanding Priorities</strong></h3><p>Processes in Linux are assigned priorities that influence their scheduling:</p><ol><li><p><strong>Nice Values</strong>:</p><ul><li><p>Range: <strong>-20</strong> (highest priority) to <strong>19</strong> (lowest priority).</p></li><li><p>A lower nice value means the process gets more CPU time.</p></li></ul></li></ol><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!lz30!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c932920-ba70-4551-95ed-7a27402e0701_453x127.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!lz30!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c932920-ba70-4551-95ed-7a27402e0701_453x127.png 424w, https://substackcdn.com/image/fetch/$s_!lz30!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c932920-ba70-4551-95ed-7a27402e0701_453x127.png 848w, https://substackcdn.com/image/fetch/$s_!lz30!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c932920-ba70-4551-95ed-7a27402e0701_453x127.png 1272w, https://substackcdn.com/image/fetch/$s_!lz30!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c932920-ba70-4551-95ed-7a27402e0701_453x127.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!lz30!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c932920-ba70-4551-95ed-7a27402e0701_453x127.png" width="453" height="127" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9c932920-ba70-4551-95ed-7a27402e0701_453x127.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:127,&quot;width&quot;:453,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:5105,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!lz30!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c932920-ba70-4551-95ed-7a27402e0701_453x127.png 424w, https://substackcdn.com/image/fetch/$s_!lz30!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c932920-ba70-4551-95ed-7a27402e0701_453x127.png 848w, https://substackcdn.com/image/fetch/$s_!lz30!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c932920-ba70-4551-95ed-7a27402e0701_453x127.png 1272w, https://substackcdn.com/image/fetch/$s_!lz30!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c932920-ba70-4551-95ed-7a27402e0701_453x127.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><ol start="2"><li><p><strong>Real-Time Priorities</strong>:</p></li></ol><ul><li><p>Range: <strong>1</strong> (lowest) to <strong>99</strong> (highest).</p></li><li><p>Used only by real-time scheduling policies (<code>SCHED_FIFO</code> and <code>SCHED_RR</code>).</p></li></ul><p>If you feel that the program is taking too much of the resources, you can change the scheduling priority of that process using renice command.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!5o_L!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c59d19a-3411-4f74-b535-a4d0c10a6695_626x112.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!5o_L!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c59d19a-3411-4f74-b535-a4d0c10a6695_626x112.png 424w, https://substackcdn.com/image/fetch/$s_!5o_L!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c59d19a-3411-4f74-b535-a4d0c10a6695_626x112.png 848w, https://substackcdn.com/image/fetch/$s_!5o_L!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c59d19a-3411-4f74-b535-a4d0c10a6695_626x112.png 1272w, https://substackcdn.com/image/fetch/$s_!5o_L!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c59d19a-3411-4f74-b535-a4d0c10a6695_626x112.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!5o_L!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c59d19a-3411-4f74-b535-a4d0c10a6695_626x112.png" width="626" height="112" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3c59d19a-3411-4f74-b535-a4d0c10a6695_626x112.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:112,&quot;width&quot;:626,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:5381,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!5o_L!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c59d19a-3411-4f74-b535-a4d0c10a6695_626x112.png 424w, https://substackcdn.com/image/fetch/$s_!5o_L!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c59d19a-3411-4f74-b535-a4d0c10a6695_626x112.png 848w, https://substackcdn.com/image/fetch/$s_!5o_L!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c59d19a-3411-4f74-b535-a4d0c10a6695_626x112.png 1272w, https://substackcdn.com/image/fetch/$s_!5o_L!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c59d19a-3411-4f74-b535-a4d0c10a6695_626x112.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>This feature combined with tools like top can help in identifying and changing scheduling priorities of resource intense processes.</p><div class="embedded-post-wrap" data-attrs="{&quot;id&quot;:152312421,&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/p/threads-in-linux-a-comprehensive&quot;,&quot;publication_id&quot;:3043184,&quot;publication_name&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd74e8425-0a13-40ad-86b5-27bdf5afe57f_800x800.png&quot;,&quot;title&quot;:&quot;Threads in Linux: A Comprehensive Guide&quot;,&quot;truncated_body_text&quot;:&quot;In modern computing, threads play a vital role in achieving concurrency and parallelism. Threads are lightweight entities within processes that share the same memory space but can execute independently. This blog explores what threads are, their advantages, how the Linux kernel manages threads through the Thread Control Block (TCB), their lifecycle, and&#8230;&quot;,&quot;date&quot;:&quot;2024-11-29T07:59:58.911Z&quot;,&quot;like_count&quot;:0,&quot;comment_count&quot;:0,&quot;bylines&quot;:[{&quot;id&quot;:114001497,&quot;name&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;handle&quot;:&quot;gopakumarrajappan&quot;,&quot;previous_name&quot;:null,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e0e7bbb2-d0a8-45af-9002-89ad7c317651_800x800.jpeg&quot;,&quot;bio&quot;:&quot;Programming, Computer Networks, Distributed systems&quot;,&quot;profile_set_up_at&quot;:&quot;2024-09-19T19:51:04.852Z&quot;,&quot;publicationUsers&quot;:[{&quot;id&quot;:3096759,&quot;user_id&quot;:114001497,&quot;publication_id&quot;:3043184,&quot;role&quot;:&quot;admin&quot;,&quot;public&quot;:true,&quot;is_primary&quot;:false,&quot;publication&quot;:{&quot;id&quot;:3043184,&quot;name&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;subdomain&quot;:&quot;gopakumarrajappan&quot;,&quot;custom_domain&quot;:&quot;www.gopakumar-rajappan.com&quot;,&quot;custom_domain_optional&quot;:false,&quot;hero_text&quot;:&quot;First Principles: A Guiding Path to Understanding Tech Advancements&quot;,&quot;logo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d74e8425-0a13-40ad-86b5-27bdf5afe57f_800x800.png&quot;,&quot;author_id&quot;:114001497,&quot;theme_var_background_pop&quot;:&quot;#FF6719&quot;,&quot;created_at&quot;:&quot;2024-09-19T19:51:30.712Z&quot;,&quot;rss_website_url&quot;:null,&quot;email_from_name&quot;:null,&quot;copyright&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;founding_plan_name&quot;:null,&quot;community_enabled&quot;:true,&quot;invite_only&quot;:false,&quot;payments_state&quot;:&quot;enabled&quot;,&quot;language&quot;:null,&quot;explicit&quot;:false,&quot;is_personal_mode&quot;:false}}],&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;utm_campaign&quot;:null,&quot;belowTheFold&quot;:true,&quot;type&quot;:&quot;newsletter&quot;,&quot;language&quot;:&quot;en&quot;,&quot;source&quot;:null}" data-component-name="EmbeddedPostToDOM"><a class="embedded-post" native="true" href="https://www.gopakumar-rajappan.com/p/threads-in-linux-a-comprehensive?utm_source=substack&amp;utm_campaign=post_embed&amp;utm_medium=web"><div class="embedded-post-header"><img class="embedded-post-publication-logo" src="https://substackcdn.com/image/fetch/$s_!0BMm!,w_56,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd74e8425-0a13-40ad-86b5-27bdf5afe57f_800x800.png" loading="lazy"><span class="embedded-post-publication-name">GOPAKUMAR RAJAPPAN</span></div><div class="embedded-post-title-wrapper"><div class="embedded-post-title">Threads in Linux: A Comprehensive Guide</div></div><div class="embedded-post-body">In modern computing, threads play a vital role in achieving concurrency and parallelism. Threads are lightweight entities within processes that share the same memory space but can execute independently. This blog explores what threads are, their advantages, how the Linux kernel manages threads through the Thread Control Block (TCB), their lifecycle, and&#8230;</div><div class="embedded-post-cta-wrapper"><span class="embedded-post-cta">Read more</span></div><div class="embedded-post-meta">a year ago &#183; GOPAKUMAR RAJAPPAN</div></a></div><p><br></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">GOPAKUMAR RAJAPPAN is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Threads in Linux: A Comprehensive Guide]]></title><description><![CDATA[In modern computing, threads play a vital role in achieving concurrency and parallelism.]]></description><link>https://www.gopakumar-rajappan.com/p/threads-in-linux-a-comprehensive</link><guid isPermaLink="false">https://www.gopakumar-rajappan.com/p/threads-in-linux-a-comprehensive</guid><dc:creator><![CDATA[GOPAKUMAR RAJAPPAN]]></dc:creator><pubDate>Fri, 29 Nov 2024 07:59:58 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!FJj_!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c168c37-430d-4751-afe5-ef7a1d770cc7_1024x1024.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!FJj_!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c168c37-430d-4751-afe5-ef7a1d770cc7_1024x1024.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!FJj_!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c168c37-430d-4751-afe5-ef7a1d770cc7_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!FJj_!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c168c37-430d-4751-afe5-ef7a1d770cc7_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!FJj_!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c168c37-430d-4751-afe5-ef7a1d770cc7_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!FJj_!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c168c37-430d-4751-afe5-ef7a1d770cc7_1024x1024.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!FJj_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c168c37-430d-4751-afe5-ef7a1d770cc7_1024x1024.webp" width="1024" height="1024" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8c168c37-430d-4751-afe5-ef7a1d770cc7_1024x1024.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:445300,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/webp&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!FJj_!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c168c37-430d-4751-afe5-ef7a1d770cc7_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!FJj_!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c168c37-430d-4751-afe5-ef7a1d770cc7_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!FJj_!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c168c37-430d-4751-afe5-ef7a1d770cc7_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!FJj_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c168c37-430d-4751-afe5-ef7a1d770cc7_1024x1024.webp 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>In modern computing, threads play a vital role in achieving concurrency and parallelism. Threads are lightweight entities within processes that share the same memory space but can execute independently. This blog explores what threads are, their advantages, how the Linux kernel manages threads through the Thread Control Block (TCB), their lifecycle, and best practices for developers and administrators.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">GOPAKUMAR RAJAPPAN is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h3><strong>What is a Thread?</strong></h3><p>A <strong>thread</strong> is the smallest unit of execution within a process. Unlike processes, threads within the same process share:</p><ul><li><p><strong>Memory space</strong>: Threads share the same address space, global variables, and heap.</p></li><li><p><strong>Open file descriptors</strong>: Threads can access the same files or sockets as other threads in the process.</p></li><li><p><strong>Execution privileges</strong>: Threads inherit the process's user ID (UID) and group ID (GID).</p></li></ul><h4><strong>Key Characteristics of Threads</strong></h4><ol><li><p><strong>Lightweight</strong>:</p><ul><li><p>Creating and switching threads is faster and requires fewer resources compared to processes.</p></li></ul></li><li><p><strong>Shared Resources</strong>:</p><ul><li><p>Threads within a process share memory and system resources, enabling efficient communication.</p></li></ul></li><li><p><strong>Independent Execution</strong>:</p><ul><li><p>Each thread has its own <strong>execution context</strong> (e.g., program counter, stack, and CPU registers).</p></li></ul></li></ol><div><hr></div><h3><strong>Advantages of Threads</strong></h3><ol><li><p><strong>Improved Performance</strong>:</p><ul><li><p>Threads enable better utilization of multi-core processors by allowing parallel execution of tasks.</p></li><li><p>Example: A web server can use threads to handle multiple client requests simultaneously.</p></li></ul></li><li><p><strong>Efficient Communication</strong>:</p><ul><li><p>Since threads share the same memory, they can communicate without the overhead of inter-process communication (IPC).</p></li></ul></li><li><p><strong>Scalability</strong>:</p><ul><li><p>Threads can scale well in multi-core systems, distributing workloads across available cores.</p></li></ul></li><li><p><strong>Responsiveness</strong>:</p><ul><li><p>Threads allow GUI applications to remain responsive by delegating long-running tasks (e.g., file downloads) to background threads.</p></li></ul></li></ol><div><hr></div><h3><strong>How the Kernel Manages Threads</strong></h3><p>The Linux kernel manages threads using a data structure called the <strong>Thread Control Block (TCB)</strong>. Threads are treated as <strong>lightweight processes</strong> in Linux and are managed similarly to processes, with each thread having its own TCB.</p><h4><strong>The Thread Control Block (TCB)</strong></h4><p>The TCB is a data structure that stores information specific to a thread. It is linked to the <strong>Process Control Block (PCB)</strong> of the parent process to share common resources.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!MWoo!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf365dd0-51f3-47db-b8a1-cf6e5767421b_921x485.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!MWoo!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf365dd0-51f3-47db-b8a1-cf6e5767421b_921x485.png 424w, https://substackcdn.com/image/fetch/$s_!MWoo!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf365dd0-51f3-47db-b8a1-cf6e5767421b_921x485.png 848w, https://substackcdn.com/image/fetch/$s_!MWoo!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf365dd0-51f3-47db-b8a1-cf6e5767421b_921x485.png 1272w, https://substackcdn.com/image/fetch/$s_!MWoo!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf365dd0-51f3-47db-b8a1-cf6e5767421b_921x485.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!MWoo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf365dd0-51f3-47db-b8a1-cf6e5767421b_921x485.png" width="921" height="485" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cf365dd0-51f3-47db-b8a1-cf6e5767421b_921x485.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:485,&quot;width&quot;:921,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:51545,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!MWoo!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf365dd0-51f3-47db-b8a1-cf6e5767421b_921x485.png 424w, https://substackcdn.com/image/fetch/$s_!MWoo!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf365dd0-51f3-47db-b8a1-cf6e5767421b_921x485.png 848w, https://substackcdn.com/image/fetch/$s_!MWoo!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf365dd0-51f3-47db-b8a1-cf6e5767421b_921x485.png 1272w, https://substackcdn.com/image/fetch/$s_!MWoo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf365dd0-51f3-47db-b8a1-cf6e5767421b_921x485.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h4><strong>Relationship Between PCB and TCB</strong></h4><ul><li><p>The <strong>Process Control Block (PCB)</strong> holds global information for the entire process, including all threads.</p></li><li><p>Each thread within the process has its own <strong>Thread Control Block (TCB)</strong>, which stores thread-specific data (e.g., program counter, stack pointer).</p></li><li><p><strong>Shared Resources</strong>:</p><ul><li><p>Memory mappings, file descriptors, and process-level attributes (e.g., UID, GID) are stored in the PCB and shared by all TCBs linked to it.</p></li></ul></li></ul><h3><strong>Thread Lifecycle</strong></h3><p>Similar to processes, threads have a lifecycle, but transitions are lighter and faster.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!nI-W!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27c95f2e-3297-461e-bf6c-b5d081fb9ada_941x270.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!nI-W!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27c95f2e-3297-461e-bf6c-b5d081fb9ada_941x270.png 424w, https://substackcdn.com/image/fetch/$s_!nI-W!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27c95f2e-3297-461e-bf6c-b5d081fb9ada_941x270.png 848w, https://substackcdn.com/image/fetch/$s_!nI-W!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27c95f2e-3297-461e-bf6c-b5d081fb9ada_941x270.png 1272w, https://substackcdn.com/image/fetch/$s_!nI-W!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27c95f2e-3297-461e-bf6c-b5d081fb9ada_941x270.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!nI-W!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27c95f2e-3297-461e-bf6c-b5d081fb9ada_941x270.png" width="941" height="270" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/27c95f2e-3297-461e-bf6c-b5d081fb9ada_941x270.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:270,&quot;width&quot;:941,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:30949,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!nI-W!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27c95f2e-3297-461e-bf6c-b5d081fb9ada_941x270.png 424w, https://substackcdn.com/image/fetch/$s_!nI-W!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27c95f2e-3297-461e-bf6c-b5d081fb9ada_941x270.png 848w, https://substackcdn.com/image/fetch/$s_!nI-W!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27c95f2e-3297-461e-bf6c-b5d081fb9ada_941x270.png 1272w, https://substackcdn.com/image/fetch/$s_!nI-W!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27c95f2e-3297-461e-bf6c-b5d081fb9ada_941x270.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h4><strong>State Transitions</strong></h4><ul><li><p><strong>New &#8594; Runnable</strong>: The thread is created and added to the <strong>Ready Queue</strong>.</p></li><li><p><strong>Runnable &#8594; Running</strong>: The scheduler picks the thread from the <strong>Ready Queue</strong> and assigns it to the CPU.</p></li><li><p><strong>Running &#8594; Waiting</strong>: The thread waits for an event (e.g., I/O or a signal).</p></li><li><p><strong>Running &#8594; Terminated</strong>: The thread completes execution and terminates.</p></li></ul><div><hr></div><h3><strong>Utilities for Managing Threads</strong></h3><p>Linux provides tools and utilities for monitoring and managing threads:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!9Xwg!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F658b2e60-469b-4c98-aaf7-06ada5782079_917x358.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!9Xwg!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F658b2e60-469b-4c98-aaf7-06ada5782079_917x358.png 424w, https://substackcdn.com/image/fetch/$s_!9Xwg!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F658b2e60-469b-4c98-aaf7-06ada5782079_917x358.png 848w, https://substackcdn.com/image/fetch/$s_!9Xwg!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F658b2e60-469b-4c98-aaf7-06ada5782079_917x358.png 1272w, https://substackcdn.com/image/fetch/$s_!9Xwg!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F658b2e60-469b-4c98-aaf7-06ada5782079_917x358.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!9Xwg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F658b2e60-469b-4c98-aaf7-06ada5782079_917x358.png" width="917" height="358" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/658b2e60-469b-4c98-aaf7-06ada5782079_917x358.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:358,&quot;width&quot;:917,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:31868,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!9Xwg!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F658b2e60-469b-4c98-aaf7-06ada5782079_917x358.png 424w, https://substackcdn.com/image/fetch/$s_!9Xwg!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F658b2e60-469b-4c98-aaf7-06ada5782079_917x358.png 848w, https://substackcdn.com/image/fetch/$s_!9Xwg!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F658b2e60-469b-4c98-aaf7-06ada5782079_917x358.png 1272w, https://substackcdn.com/image/fetch/$s_!9Xwg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F658b2e60-469b-4c98-aaf7-06ada5782079_917x358.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3><strong>Recommendations for Developers and Administrators</strong></h3><h4><strong>For Developers</strong></h4><ol><li><p><strong>Minimize Synchronization Overhead</strong>:</p><ul><li><p>Use fine-grained locks or lock-free data structures to reduce contention.</p></li><li><p>Avoid deadlocks by following consistent locking order.</p></li></ul></li><li><p><strong>Use Thread Pools</strong>:</p><ul><li><p>Reuse threads for multiple tasks instead of creating and destroying threads repeatedly.</p></li></ul></li><li><p><strong>Thread Safety</strong>:</p><ul><li><p>Ensure shared resources are accessed safely using mutexes, semaphores, or atomic variables.</p></li></ul></li><li><p><strong>Leverage Libraries</strong>:</p><ul><li><p>Use libraries like <code>pthread</code> or higher-level abstractions (e.g., OpenMP, C++ threads) for easier thread management.</p></li></ul></li></ol><div><hr></div><h4><strong>For Administrators</strong></h4><ol><li><p><strong>Monitor Thread Usage</strong>:</p><ul><li><p>Use tools like <code>htop</code> or <code>ps</code> to track thread count and ensure threads don&#8217;t overwhelm system resources.</p></li></ul></li><li><p><strong>Set Limits</strong>:</p><ul><li><p>Configure thread limits in <code>/etc/security/limits.conf</code> to prevent runaway processes from creating excessive threads.</p></li></ul></li><li><p><strong>Debugging</strong>:</p><ul><li><p>Use <code>gdb</code> and <code>/proc/&lt;PID&gt;/task</code> to debug issues in multi-threaded programs.</p></li></ul></li><li><p><strong>Analyze Performance</strong>:</p><ul><li><p>Profile applications using tools like <code>perf</code> to identify thread-related bottlenecks.</p></li></ul></li></ol><div><hr></div><h3><strong>Conclusion</strong></h3><p>Threads are powerful tools for achieving concurrency and parallelism in modern applications. By understanding how threads are managed by the Linux kernel through <strong>Thread Control Blocks (TCBs)</strong> and their relationship with the <strong>Process Control Block (PCB)</strong>, developers and administrators can write efficient, scalable, and robust applications. Proper monitoring and debugging utilities further ensure thread safety and performance optimization.</p><p>Threads are the backbone of many high-performance systems, and mastering them is crucial for both system architects and developers.</p><div class="embedded-post-wrap" data-attrs="{&quot;id&quot;:152336717,&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/p/memory-management-in-linux&quot;,&quot;publication_id&quot;:3043184,&quot;publication_name&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd74e8425-0a13-40ad-86b5-27bdf5afe57f_800x800.png&quot;,&quot;title&quot;:&quot;Memory Management in Linux&quot;,&quot;truncated_body_text&quot;:&quot;Memory management is one of the most critical functions of the Linux kernel. It ensures that every process has the memory it needs to run while optimizing overall system performance. In this context, memory refers to RAM (Random Access Memory), which is the fast, volatile memory used to store data and instructions currently being executed by the CPU. Th&#8230;&quot;,&quot;date&quot;:&quot;2024-11-29T21:49:19.060Z&quot;,&quot;like_count&quot;:0,&quot;comment_count&quot;:0,&quot;bylines&quot;:[{&quot;id&quot;:114001497,&quot;name&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;handle&quot;:&quot;gopakumarrajappan&quot;,&quot;previous_name&quot;:null,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e0e7bbb2-d0a8-45af-9002-89ad7c317651_800x800.jpeg&quot;,&quot;bio&quot;:&quot;Programming, Computer Networks, Distributed systems&quot;,&quot;profile_set_up_at&quot;:&quot;2024-09-19T19:51:04.852Z&quot;,&quot;publicationUsers&quot;:[{&quot;id&quot;:3096759,&quot;user_id&quot;:114001497,&quot;publication_id&quot;:3043184,&quot;role&quot;:&quot;admin&quot;,&quot;public&quot;:true,&quot;is_primary&quot;:false,&quot;publication&quot;:{&quot;id&quot;:3043184,&quot;name&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;subdomain&quot;:&quot;gopakumarrajappan&quot;,&quot;custom_domain&quot;:&quot;www.gopakumar-rajappan.com&quot;,&quot;custom_domain_optional&quot;:false,&quot;hero_text&quot;:&quot;First Principles: A Guiding Path to Understanding Tech Advancements&quot;,&quot;logo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d74e8425-0a13-40ad-86b5-27bdf5afe57f_800x800.png&quot;,&quot;author_id&quot;:114001497,&quot;theme_var_background_pop&quot;:&quot;#FF6719&quot;,&quot;created_at&quot;:&quot;2024-09-19T19:51:30.712Z&quot;,&quot;rss_website_url&quot;:null,&quot;email_from_name&quot;:null,&quot;copyright&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;founding_plan_name&quot;:null,&quot;community_enabled&quot;:true,&quot;invite_only&quot;:false,&quot;payments_state&quot;:&quot;enabled&quot;,&quot;language&quot;:null,&quot;explicit&quot;:false,&quot;is_personal_mode&quot;:false}}],&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;utm_campaign&quot;:null,&quot;belowTheFold&quot;:true,&quot;type&quot;:&quot;newsletter&quot;,&quot;language&quot;:&quot;en&quot;,&quot;source&quot;:null}" data-component-name="EmbeddedPostToDOM"><a class="embedded-post" native="true" href="https://www.gopakumar-rajappan.com/p/memory-management-in-linux?utm_source=substack&amp;utm_campaign=post_embed&amp;utm_medium=web"><div class="embedded-post-header"><img class="embedded-post-publication-logo" src="https://substackcdn.com/image/fetch/$s_!0BMm!,w_56,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd74e8425-0a13-40ad-86b5-27bdf5afe57f_800x800.png" loading="lazy"><span class="embedded-post-publication-name">GOPAKUMAR RAJAPPAN</span></div><div class="embedded-post-title-wrapper"><div class="embedded-post-title">Memory Management in Linux</div></div><div class="embedded-post-body">Memory management is one of the most critical functions of the Linux kernel. It ensures that every process has the memory it needs to run while optimizing overall system performance. In this context, memory refers to RAM (Random Access Memory), which is the fast, volatile memory used to store data and instructions currently being executed by the CPU. Th&#8230;</div><div class="embedded-post-cta-wrapper"><span class="embedded-post-cta">Read more</span></div><div class="embedded-post-meta">a year ago &#183; GOPAKUMAR RAJAPPAN</div></a></div><p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">GOPAKUMAR RAJAPPAN is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Programs and Process in Linux - 3]]></title><description><![CDATA[How the Linux Kernel Manages Multiple Processes]]></description><link>https://www.gopakumar-rajappan.com/p/programs-and-process-in-linux-3</link><guid isPermaLink="false">https://www.gopakumar-rajappan.com/p/programs-and-process-in-linux-3</guid><dc:creator><![CDATA[GOPAKUMAR RAJAPPAN]]></dc:creator><pubDate>Fri, 29 Nov 2024 07:47:39 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!dw9e!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97e1aa94-a366-411a-a557-3436c83484ce_928x498.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3><strong>How the Linux Kernel Manages Multiple Processes</strong></h3><p>The Linux kernel is designed to handle multitasking, where multiple processes execute seemingly simultaneously. To achieve this, the kernel uses sophisticated mechanisms to manage processes, track their state, and allocate system resources like CPU, memory, and I/O devices. This blog explains how the kernel manages multiple processes through <strong>Process Control Blocks (PCBs)</strong> and the <strong>process lifecycle</strong>, along with key terms and concepts.</p><h3><strong>What is a Process Control Block (PCB)?</strong></h3><p>A <strong>Process Control Block (PCB)</strong> is a data structure maintained by the kernel for every process in the system. The PCB acts as the identity card for a process, storing all the information the kernel needs to manage it.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">GOPAKUMAR RAJAPPAN is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h4><strong>Contents of a PCB</strong></h4><p>Here&#8217;s what a PCB typically contains:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!dw9e!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97e1aa94-a366-411a-a557-3436c83484ce_928x498.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!dw9e!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97e1aa94-a366-411a-a557-3436c83484ce_928x498.png 424w, https://substackcdn.com/image/fetch/$s_!dw9e!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97e1aa94-a366-411a-a557-3436c83484ce_928x498.png 848w, https://substackcdn.com/image/fetch/$s_!dw9e!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97e1aa94-a366-411a-a557-3436c83484ce_928x498.png 1272w, https://substackcdn.com/image/fetch/$s_!dw9e!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97e1aa94-a366-411a-a557-3436c83484ce_928x498.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!dw9e!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97e1aa94-a366-411a-a557-3436c83484ce_928x498.png" width="928" height="498" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/97e1aa94-a366-411a-a557-3436c83484ce_928x498.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:498,&quot;width&quot;:928,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:60928,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!dw9e!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97e1aa94-a366-411a-a557-3436c83484ce_928x498.png 424w, https://substackcdn.com/image/fetch/$s_!dw9e!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97e1aa94-a366-411a-a557-3436c83484ce_928x498.png 848w, https://substackcdn.com/image/fetch/$s_!dw9e!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97e1aa94-a366-411a-a557-3436c83484ce_928x498.png 1272w, https://substackcdn.com/image/fetch/$s_!dw9e!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97e1aa94-a366-411a-a557-3436c83484ce_928x498.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3>The Process Lifecycle</h3><p>The kernel manages a process through its lifecycle, transitioning it between different states based on its current activity and system conditions.</p><h4><strong>Process States</strong></h4><p>In Linux, a process can exist in one of several states:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!HGcI!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F552b5348-7e85-4552-868f-286861aaaf01_917x480.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!HGcI!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F552b5348-7e85-4552-868f-286861aaaf01_917x480.png 424w, https://substackcdn.com/image/fetch/$s_!HGcI!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F552b5348-7e85-4552-868f-286861aaaf01_917x480.png 848w, https://substackcdn.com/image/fetch/$s_!HGcI!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F552b5348-7e85-4552-868f-286861aaaf01_917x480.png 1272w, https://substackcdn.com/image/fetch/$s_!HGcI!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F552b5348-7e85-4552-868f-286861aaaf01_917x480.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!HGcI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F552b5348-7e85-4552-868f-286861aaaf01_917x480.png" width="917" height="480" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/552b5348-7e85-4552-868f-286861aaaf01_917x480.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:480,&quot;width&quot;:917,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:51310,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!HGcI!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F552b5348-7e85-4552-868f-286861aaaf01_917x480.png 424w, https://substackcdn.com/image/fetch/$s_!HGcI!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F552b5348-7e85-4552-868f-286861aaaf01_917x480.png 848w, https://substackcdn.com/image/fetch/$s_!HGcI!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F552b5348-7e85-4552-868f-286861aaaf01_917x480.png 1272w, https://substackcdn.com/image/fetch/$s_!HGcI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F552b5348-7e85-4552-868f-286861aaaf01_917x480.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h4><strong>Lifecycle Transitions</strong></h4><h3><strong>1. Process Creation</strong></h3><p>When a process is created, the kernel initializes it and prepares it for execution. This phase involves setting up the <strong>Process Control Block (PCB)</strong> and allocating necessary resources.</p><h4><strong>Linux-Specific States</strong>:</h4><ul><li><p><strong>New</strong>:</p><ul><li><p>The process is being created by a parent process (e.g., via the <code>fork()</code> system call).</p></li><li><p>The kernel assigns a unique Process ID (PID) and initializes the process&#8217;s context.</p></li></ul></li><li><p><strong>Runnable</strong>:</p><ul><li><p>Once initialization is complete, the process enters the <strong>Runnable Queue</strong> (also called the <strong>Ready Queue</strong>) and waits for the CPU.</p></li></ul></li></ul><h4><strong>Transitions</strong>:</h4><ul><li><p><strong>New &#8594; Runnable</strong>:</p><ul><li><p>The process transitions from the <strong>New</strong> state to the <strong>Runnable</strong> state once it&#8217;s ready for execution.</p></li><li><p>The kernel places it in the <strong>Ready Queue</strong>, where it waits for the scheduler to assign it CPU time.</p></li></ul></li></ul><h4><strong>Example</strong>:</h4><ul><li><p>When you type <code>ls</code> in the terminal, the shell forks a child process. The new process starts in the <strong>New</strong> state and transitions to <strong>Runnable</strong>.</p></li></ul><div><hr></div><h3><strong>2. Process Execution</strong></h3><p>Once the kernel&#8217;s scheduler selects the process from the <strong>Ready Queue</strong>, it begins execution on the CPU. This phase involves actual computation or instruction execution.</p><h4><strong>Linux-Specific States</strong>:</h4><ul><li><p><strong>Running</strong>:</p><ul><li><p>The process is actively executing instructions on the CPU.</p></li><li><p>It uses system resources like memory and registers during this phase.</p></li></ul></li><li><p><strong>Runnable</strong> (preempted):</p><ul><li><p>If the process is interrupted (e.g., its time slice expires), it transitions back to the <strong>Runnable Queue</strong> to wait for its next turn on the CPU.</p></li></ul></li></ul><h4><strong>Transitions</strong>:</h4><ol><li><p><strong>Runnable &#8594; Running</strong>:</p><ul><li><p>The kernel&#8217;s scheduler selects the process from the <strong>Ready Queue</strong> and assigns it CPU time.</p></li></ul></li><li><p><strong>Running &#8594; Runnable</strong>:</p><ul><li><p>The process is preempted (e.g., a higher-priority process interrupts it or its time slice ends) and returns to the <strong>Ready Queue</strong>.</p></li></ul></li></ol><h4><strong>Example</strong>:</h4><ul><li><p>The <code>ls</code> process starts executing and enters the <strong>Running</strong> state. If another process preempts it, <code>ls</code> moves back to <strong>Runnable</strong>.</p></li></ul><div><hr></div><h3><strong>3. Process Waiting</strong></h3><p>During execution, a process may need to pause while waiting for an event, such as I/O completion or a signal. In this case, the process transitions to the <strong>Waiting Queue</strong>.</p><h4><strong>Linux-Specific States</strong>:</h4><ul><li><p><strong>Sleeping</strong>:</p><ul><li><p><strong>Interruptible Sleep (S)</strong>: The process can be woken up by a signal or event.</p></li><li><p><strong>Uninterruptible Sleep (D)</strong>: The process waits for a critical, non-interruptible event (e.g., disk I/O).</p></li></ul></li><li><p><strong>Stopped</strong>:</p><ul><li><p>The process is paused and does not consume CPU resources. This can happen if a <code>SIGSTOP</code> signal is sent.</p></li></ul></li></ul><h4><strong>Transitions</strong>:</h4><ol><li><p><strong>Running &#8594; Sleeping</strong>:</p><ul><li><p>A process moves to the <strong>Sleeping</strong> state if it needs to wait for an I/O operation or event.</p></li></ul></li><li><p><strong>Sleeping &#8594; Runnable</strong>:</p><ul><li><p>Once the event completes (e.g., I/O finishes), the process moves back to the <strong>Runnable Queue</strong>.</p></li></ul></li><li><p><strong>Running &#8594; Stopped</strong>:</p><ul><li><p>A process is paused when it receives a <code>SIGSTOP</code> signal.</p></li></ul></li><li><p><strong>Stopped &#8594; Runnable</strong>:</p><ul><li><p>The process resumes when it receives a <code>SIGCONT</code> signal.</p></li></ul></li></ol><h4><strong>Example</strong>:</h4><ul><li><p>The <code>ls</code> process accesses the filesystem to read directory contents. While waiting for disk I/O to complete, it transitions to <strong>Sleeping</strong>. Once the I/O is done, it moves back to <strong>Runnable</strong>.</p></li></ul><div><hr></div><h3><strong>4. Process Termination</strong></h3><p>When a process completes its task or is terminated, it moves into the <strong>Terminated</strong> state. In some cases, it may briefly become a <strong>Zombie</strong>.</p><h4><strong>Linux-Specific States</strong>:</h4><ul><li><p><strong>Terminated</strong>:</p><ul><li><p>The process has finished execution, and the kernel cleans up its resources (e.g., memory, file descriptors).</p></li></ul></li><li><p><strong>Zombie</strong>:</p><ul><li><p>After termination, the process remains as a zombie until its parent collects its exit status using <code>wait()</code>.</p></li></ul></li></ul><h4><strong>Transitions</strong>:</h4><ol><li><p><strong>Running &#8594; Terminated</strong>:</p><ul><li><p>The process completes execution or is forcefully terminated (e.g., via <code>SIGKILL</code>).</p></li></ul></li><li><p><strong>Terminated &#8594; Zombie</strong>:</p><ul><li><p>The process becomes a zombie if the parent hasn&#8217;t retrieved its exit status.</p></li></ul></li></ol><h4><strong>Example</strong>:</h4><ul><li><p>The <code>ls</code> process completes execution and transitions to <strong>Terminated</strong>. If the shell doesn&#8217;t immediately retrieve its exit status, <code>ls</code> briefly becomes a <strong>Zombie</strong>.</p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!0fWS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32bb2af9-60a6-45a6-abed-ead6822f666e_898x502.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!0fWS!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32bb2af9-60a6-45a6-abed-ead6822f666e_898x502.png 424w, https://substackcdn.com/image/fetch/$s_!0fWS!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32bb2af9-60a6-45a6-abed-ead6822f666e_898x502.png 848w, https://substackcdn.com/image/fetch/$s_!0fWS!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32bb2af9-60a6-45a6-abed-ead6822f666e_898x502.png 1272w, https://substackcdn.com/image/fetch/$s_!0fWS!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32bb2af9-60a6-45a6-abed-ead6822f666e_898x502.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!0fWS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32bb2af9-60a6-45a6-abed-ead6822f666e_898x502.png" width="898" height="502" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/32bb2af9-60a6-45a6-abed-ead6822f666e_898x502.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:502,&quot;width&quot;:898,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:70954,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!0fWS!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32bb2af9-60a6-45a6-abed-ead6822f666e_898x502.png 424w, https://substackcdn.com/image/fetch/$s_!0fWS!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32bb2af9-60a6-45a6-abed-ead6822f666e_898x502.png 848w, https://substackcdn.com/image/fetch/$s_!0fWS!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32bb2af9-60a6-45a6-abed-ead6822f666e_898x502.png 1272w, https://substackcdn.com/image/fetch/$s_!0fWS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32bb2af9-60a6-45a6-abed-ead6822f666e_898x502.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><div><hr></div><h3><strong>Key Terms to Understand</strong></h3><h4><strong>1. Context Switching</strong></h4><ul><li><p><strong>What is it?</strong><br>Context switching is the mechanism by which the kernel saves the state of a currently running process and restores the state of another process, allowing multitasking.</p></li><li><p><strong>Why is it needed?</strong><br>It enables the CPU to execute multiple processes by switching between them rapidly.</p></li><li><p><strong>What happens during a context switch?</strong></p><ul><li><p>The kernel saves the current process's state (e.g., program counter, CPU registers) in its PCB.</p></li><li><p>It loads the state of the next process from its PCB.</p></li></ul></li></ul><div><hr></div><h4><strong>2. Process Scheduler</strong></h4><ul><li><p><strong>What is it?</strong><br>The process scheduler is a kernel component that decides which process to run next.</p></li><li><p><strong>Scheduling Policies</strong>:</p><ul><li><p><strong>Round-Robin</strong>: Allocates time slices to processes in a cyclic order.</p></li><li><p><strong>Priority-Based</strong>: Runs processes based on their priority.</p></li><li><p><strong>Real-Time Scheduling</strong>: Ensures time-critical processes run as required.</p></li></ul></li></ul><div><hr></div><h4><strong>3. Signals</strong></h4><ul><li><p><strong>What are signals?</strong><br>Signals are software interrupts used to communicate with or control processes.</p></li><li><p><strong>Examples</strong>:</p><ul><li><p><code>SIGKILL</code>: Forcefully terminates a process.</p></li><li><p><code>SIGSTOP</code>: Stops a process temporarily.</p></li><li><p><code>SIGCONT</code>: Resumes a stopped process.</p></li></ul></li></ul><div><hr></div><h4><strong>4. Process Table</strong></h4><ul><li><p><strong>What is it?</strong><br>The process table is a kernel data structure that maintains a list of all active PCBs. It serves as the kernel&#8217;s central repository for process management.</p></li></ul><h3><strong>Key Insights</strong></h3><ol><li><p><strong>Optimizing I/O-Bound Processes</strong>:</p><ul><li><p>For I/O-heavy workloads, developers should design programs to handle asynchronous I/O, minimizing time in the <strong>Waiting</strong> state.</p></li></ul></li><li><p><strong>Efficient CPU Utilization</strong>:</p><ul><li><p>For CPU-bound processes, understanding time slices and scheduling policies helps optimize performance by reducing time spent in the <strong>Ready Queue</strong>.</p></li></ul></li><li><p><strong>Zombie Processes</strong>:</p><ul><li><p>Developers must ensure that parent processes correctly handle child processes' exit statuses to avoid zombie accumulation.</p></li></ul></li><li><p><strong>Debugging with States</strong>:</p><ul><li><p>Use tools like <code>ps</code> and <code>/proc/&lt;PID&gt;/status</code> to inspect the state of processes during debugging.</p></li></ul></li></ol><h4>Commands for Investigating Process States</h4><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!HDnK!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc2dcb96-be98-478e-9967-a14df6aadddc_916x317.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!HDnK!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc2dcb96-be98-478e-9967-a14df6aadddc_916x317.png 424w, https://substackcdn.com/image/fetch/$s_!HDnK!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc2dcb96-be98-478e-9967-a14df6aadddc_916x317.png 848w, https://substackcdn.com/image/fetch/$s_!HDnK!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc2dcb96-be98-478e-9967-a14df6aadddc_916x317.png 1272w, https://substackcdn.com/image/fetch/$s_!HDnK!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc2dcb96-be98-478e-9967-a14df6aadddc_916x317.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!HDnK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc2dcb96-be98-478e-9967-a14df6aadddc_916x317.png" width="916" height="317" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cc2dcb96-be98-478e-9967-a14df6aadddc_916x317.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:317,&quot;width&quot;:916,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:28145,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!HDnK!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc2dcb96-be98-478e-9967-a14df6aadddc_916x317.png 424w, https://substackcdn.com/image/fetch/$s_!HDnK!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc2dcb96-be98-478e-9967-a14df6aadddc_916x317.png 848w, https://substackcdn.com/image/fetch/$s_!HDnK!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc2dcb96-be98-478e-9967-a14df6aadddc_916x317.png 1272w, https://substackcdn.com/image/fetch/$s_!HDnK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc2dcb96-be98-478e-9967-a14df6aadddc_916x317.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Understanding how the Linux kernel manages process states and transitions is critical for optimizing applications, debugging issues, and maintaining system stability. The use of <strong>queues</strong>, <strong>state transitions</strong>, and efficient scheduling ensures that Linux can handle multitasking seamlessly. Developers and system administrators can leverage this knowledge to create efficient, resource-aware applications and troubleshoot performance bottlenecks effectively.</p><div class="embedded-post-wrap" data-attrs="{&quot;id&quot;:152312694,&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/p/process-scheduling-in-linux&quot;,&quot;publication_id&quot;:3043184,&quot;publication_name&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd74e8425-0a13-40ad-86b5-27bdf5afe57f_800x800.png&quot;,&quot;title&quot;:&quot;Process Scheduling in Linux&quot;,&quot;truncated_body_text&quot;:&quot;When multiple processes and threads are running on a Linux system, the kernel must decide which one gets to use the CPU and for how long. This decision-making mechanism, known as process scheduling, ensures fairness, efficiency, and responsiveness in multitasking environments. In this blog, we&#8217;ll dive into the basics of process scheduling, explore the L&#8230;&quot;,&quot;date&quot;:&quot;2024-11-29T08:17:38.401Z&quot;,&quot;like_count&quot;:0,&quot;comment_count&quot;:0,&quot;bylines&quot;:[{&quot;id&quot;:114001497,&quot;name&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;handle&quot;:&quot;gopakumarrajappan&quot;,&quot;previous_name&quot;:null,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e0e7bbb2-d0a8-45af-9002-89ad7c317651_800x800.jpeg&quot;,&quot;bio&quot;:&quot;Programming, Computer Networks, Distributed systems&quot;,&quot;profile_set_up_at&quot;:&quot;2024-09-19T19:51:04.852Z&quot;,&quot;publicationUsers&quot;:[{&quot;id&quot;:3096759,&quot;user_id&quot;:114001497,&quot;publication_id&quot;:3043184,&quot;role&quot;:&quot;admin&quot;,&quot;public&quot;:true,&quot;is_primary&quot;:false,&quot;publication&quot;:{&quot;id&quot;:3043184,&quot;name&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;subdomain&quot;:&quot;gopakumarrajappan&quot;,&quot;custom_domain&quot;:&quot;www.gopakumar-rajappan.com&quot;,&quot;custom_domain_optional&quot;:false,&quot;hero_text&quot;:&quot;First Principles: A Guiding Path to Understanding Tech Advancements&quot;,&quot;logo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d74e8425-0a13-40ad-86b5-27bdf5afe57f_800x800.png&quot;,&quot;author_id&quot;:114001497,&quot;theme_var_background_pop&quot;:&quot;#FF6719&quot;,&quot;created_at&quot;:&quot;2024-09-19T19:51:30.712Z&quot;,&quot;rss_website_url&quot;:null,&quot;email_from_name&quot;:null,&quot;copyright&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;founding_plan_name&quot;:null,&quot;community_enabled&quot;:true,&quot;invite_only&quot;:false,&quot;payments_state&quot;:&quot;enabled&quot;,&quot;language&quot;:null,&quot;explicit&quot;:false,&quot;is_personal_mode&quot;:false}}],&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;utm_campaign&quot;:null,&quot;belowTheFold&quot;:true,&quot;type&quot;:&quot;newsletter&quot;,&quot;language&quot;:&quot;en&quot;,&quot;source&quot;:null}" data-component-name="EmbeddedPostToDOM"><a class="embedded-post" native="true" href="https://www.gopakumar-rajappan.com/p/process-scheduling-in-linux?utm_source=substack&amp;utm_campaign=post_embed&amp;utm_medium=web"><div class="embedded-post-header"><img class="embedded-post-publication-logo" src="https://substackcdn.com/image/fetch/$s_!0BMm!,w_56,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd74e8425-0a13-40ad-86b5-27bdf5afe57f_800x800.png" loading="lazy"><span class="embedded-post-publication-name">GOPAKUMAR RAJAPPAN</span></div><div class="embedded-post-title-wrapper"><div class="embedded-post-title">Process Scheduling in Linux</div></div><div class="embedded-post-body">When multiple processes and threads are running on a Linux system, the kernel must decide which one gets to use the CPU and for how long. This decision-making mechanism, known as process scheduling, ensures fairness, efficiency, and responsiveness in multitasking environments. In this blog, we&#8217;ll dive into the basics of process scheduling, explore the L&#8230;</div><div class="embedded-post-cta-wrapper"><span class="embedded-post-cta">Read more</span></div><div class="embedded-post-meta">a year ago &#183; GOPAKUMAR RAJAPPAN</div></a></div><p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">GOPAKUMAR RAJAPPAN is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Programs and Processes in Linux - 2]]></title><description><![CDATA[What Happens When You Run sudo ls?]]></description><link>https://www.gopakumar-rajappan.com/p/programs-and-processes-in-linux-2</link><guid isPermaLink="false">https://www.gopakumar-rajappan.com/p/programs-and-processes-in-linux-2</guid><dc:creator><![CDATA[GOPAKUMAR RAJAPPAN]]></dc:creator><pubDate>Fri, 29 Nov 2024 07:03:25 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!mEtT!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a730075-185b-4f97-b001-fa41c0907fcc_1024x1024.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!mEtT!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a730075-185b-4f97-b001-fa41c0907fcc_1024x1024.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!mEtT!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a730075-185b-4f97-b001-fa41c0907fcc_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!mEtT!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a730075-185b-4f97-b001-fa41c0907fcc_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!mEtT!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a730075-185b-4f97-b001-fa41c0907fcc_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!mEtT!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a730075-185b-4f97-b001-fa41c0907fcc_1024x1024.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!mEtT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a730075-185b-4f97-b001-fa41c0907fcc_1024x1024.webp" width="1024" height="1024" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6a730075-185b-4f97-b001-fa41c0907fcc_1024x1024.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:367594,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/webp&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!mEtT!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a730075-185b-4f97-b001-fa41c0907fcc_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!mEtT!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a730075-185b-4f97-b001-fa41c0907fcc_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!mEtT!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a730075-185b-4f97-b001-fa41c0907fcc_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!mEtT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a730075-185b-4f97-b001-fa41c0907fcc_1024x1024.webp 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><h3><strong>What Happens When You Run </strong><code>sudo ls</code><strong>? </strong></h3><p>When you run <code>sudo ls</code>, the process creation sequence introduces an additional layer due to the role of <code>sudo</code> in handling privilege escalation. This also involves modifications to the environment variables to ensure security.</p><div><hr></div><h4><strong>1. Shell Forks a Child Process for </strong><code>sudo</code></h4><ul><li><p>When you type <code>sudo ls</code> and press Enter, the shell (e.g., <code>bash</code>) creates a new child process using the <code>fork()</code> system call.</p></li><li><p>The child process inherits:</p><ul><li><p>The parent shell's environment variables.</p></li><li><p>Open file descriptors (e.g., stdin, stdout, stderr).</p></li><li><p>Permissions (UID and GID of the user running the shell).</p></li></ul></li><li><p>After forking, the child process replaces its code with the <code>sudo</code> binary using the <code>execve()</code> system call. This means:</p><ul><li><p>The child process is now running the <code>sudo</code> program.</p></li><li><p>The parent shell process waits for the <code>sudo</code> process to complete.</p></li></ul></li></ul><div><hr></div><h4><strong>2. </strong><code>sudo</code><strong> Modifies the Environment</strong></h4><ul><li><p>Before executing the <code>ls</code> command, <code>sudo</code> makes significant changes to the environment variables to prevent privilege escalation attacks. This ensures a secure execution context.</p></li></ul><h5><strong>What Changes Does </strong><code>sudo</code><strong> Make?</strong></h5><ol><li><p><strong>Environment Variables Cleared</strong>:</p><ul><li><p>Most environment variables inherited from the shell are cleared. This includes variables like <code>$LD_PRELOAD</code> or <code>$LD_LIBRARY_PATH</code>, which could be exploited to inject malicious libraries.</p></li></ul></li><li><p><strong>Essential Variables Retained</strong>:</p><ul><li><p>A minimal set of variables is retained for compatibility:</p><ul><li><p><code>$TERM</code>: Maintains terminal settings.</p></li><li><p><code>$HOME</code>: Often set to <code>/root</code> for the root user.</p></li><li><p><code>$PATH</code>: Adjusted to include directories like <code>/sbin</code> and <code>/usr/sbin</code>, which are required for root-only commands.</p></li></ul></li><li><p>Example of modified <code>$PATH</code>:</p></li></ul></li></ol><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!dF_m!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0123e170-5601-4113-bccd-d5c05edb8986_608x90.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!dF_m!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0123e170-5601-4113-bccd-d5c05edb8986_608x90.png 424w, https://substackcdn.com/image/fetch/$s_!dF_m!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0123e170-5601-4113-bccd-d5c05edb8986_608x90.png 848w, https://substackcdn.com/image/fetch/$s_!dF_m!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0123e170-5601-4113-bccd-d5c05edb8986_608x90.png 1272w, https://substackcdn.com/image/fetch/$s_!dF_m!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0123e170-5601-4113-bccd-d5c05edb8986_608x90.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!dF_m!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0123e170-5601-4113-bccd-d5c05edb8986_608x90.png" width="608" height="90" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0123e170-5601-4113-bccd-d5c05edb8986_608x90.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:90,&quot;width&quot;:608,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:3988,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!dF_m!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0123e170-5601-4113-bccd-d5c05edb8986_608x90.png 424w, https://substackcdn.com/image/fetch/$s_!dF_m!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0123e170-5601-4113-bccd-d5c05edb8986_608x90.png 848w, https://substackcdn.com/image/fetch/$s_!dF_m!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0123e170-5601-4113-bccd-d5c05edb8986_608x90.png 1272w, https://substackcdn.com/image/fetch/$s_!dF_m!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0123e170-5601-4113-bccd-d5c05edb8986_608x90.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><ol><li><p><strong>Optional Behavior</strong>:</p><ul><li><p>If you run <code>sudo</code> with the <code>-E</code> flag (<code>sudo -E ls</code>), it preserves the parent shell's environment variables without clearing them. This can be useful but potentially insecure.</p></li></ul></li></ol><ul><li><p>At this stage, the modified environment is prepared, and <code>sudo</code> moves to execute the next process.</p></li></ul><div><hr></div><h4><strong>3. </strong><code>sudo</code><strong> Forks Another Child Process for </strong><code>ls</code></h4><ul><li><p>After verifying your credentials (via cached credentials or a password prompt), <code>sudo</code> forks another child process.</p></li><li><p>The new child process inherits the sanitized environment prepared by <code>sudo</code>.</p></li><li><p>The child&#8217;s privileges are elevated to <strong>root</strong>:</p><ul><li><p>UID is set to <code>0</code> (root user).</p></li><li><p>GID is set to <code>0</code> (root group).</p></li></ul></li><li><p>The child process replaces its code with the <code>ls</code> binary using the <code>execve()</code> system call, inheriting the adjusted environment and root-level permissions.</p></li></ul><div><hr></div><h4><strong>4. The </strong><code>ls</code><strong> Process Executes</strong></h4><ul><li><p>The <code>ls</code> process now executes with elevated privileges:</p><ul><li><p>It runs with the environment prepared by <code>sudo</code>, allowing it to access files and directories restricted to regular users.</p></li><li><p>Example: Listing files in <code>/root</code>, which would be inaccessible without root privileges.</p></li></ul></li><li><p>Once <code>ls</code> completes its execution:</p><ul><li><p>It sends an exit signal to the <code>sudo</code> process.</p></li><li><p>The <code>sudo</code> process terminates, passing control back to the original shell process.</p></li></ul></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!CCTg!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ea04ef0-38d4-4754-ac0e-e6108712319b_925x407.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!CCTg!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ea04ef0-38d4-4754-ac0e-e6108712319b_925x407.png 424w, https://substackcdn.com/image/fetch/$s_!CCTg!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ea04ef0-38d4-4754-ac0e-e6108712319b_925x407.png 848w, https://substackcdn.com/image/fetch/$s_!CCTg!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ea04ef0-38d4-4754-ac0e-e6108712319b_925x407.png 1272w, https://substackcdn.com/image/fetch/$s_!CCTg!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ea04ef0-38d4-4754-ac0e-e6108712319b_925x407.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!CCTg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ea04ef0-38d4-4754-ac0e-e6108712319b_925x407.png" width="925" height="407" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8ea04ef0-38d4-4754-ac0e-e6108712319b_925x407.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:407,&quot;width&quot;:925,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:43849,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!CCTg!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ea04ef0-38d4-4754-ac0e-e6108712319b_925x407.png 424w, https://substackcdn.com/image/fetch/$s_!CCTg!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ea04ef0-38d4-4754-ac0e-e6108712319b_925x407.png 848w, https://substackcdn.com/image/fetch/$s_!CCTg!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ea04ef0-38d4-4754-ac0e-e6108712319b_925x407.png 1272w, https://substackcdn.com/image/fetch/$s_!CCTg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ea04ef0-38d4-4754-ac0e-e6108712319b_925x407.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><ul><li></li></ul><h3><strong>Key Takeaways About Environment Changes</strong></h3><ul><li><ol><li><p><strong>Default Behavior</strong>:</p><ul><li><p><code>sudo</code> sanitizes the environment by clearing potentially dangerous variables and retaining only essential ones for security.</p></li></ul></li><li><p><strong>Customizing Behavior</strong>:</p><ul><li><p>Use the <code>-E</code> flag to retain the parent shell's environment when running commands with <code>sudo</code>.</p></li><li><p>Define environment variables to keep using the <code>env_keep</code> directive in the <code>/etc/sudoers</code> file.</p></li></ul></li><li><p><strong>Security Implications</strong>:</p><ul><li><p>Clearing the environment helps prevent privilege escalation attacks where malicious code could be injected via variables like <code>$LD_PRELOAD</code>.</p></li></ul></li></ol></li></ul><h3><strong>Revised Process Hierarchy</strong></h3><ul><li><p>Here&#8217;s the updated process flow with environment changes highlighted:</p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Viv9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4239d98e-0aff-450f-8416-d8189fb442bf_822x93.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Viv9!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4239d98e-0aff-450f-8416-d8189fb442bf_822x93.png 424w, https://substackcdn.com/image/fetch/$s_!Viv9!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4239d98e-0aff-450f-8416-d8189fb442bf_822x93.png 848w, https://substackcdn.com/image/fetch/$s_!Viv9!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4239d98e-0aff-450f-8416-d8189fb442bf_822x93.png 1272w, https://substackcdn.com/image/fetch/$s_!Viv9!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4239d98e-0aff-450f-8416-d8189fb442bf_822x93.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Viv9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4239d98e-0aff-450f-8416-d8189fb442bf_822x93.png" width="822" height="93" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4239d98e-0aff-450f-8416-d8189fb442bf_822x93.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:93,&quot;width&quot;:822,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:8691,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!Viv9!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4239d98e-0aff-450f-8416-d8189fb442bf_822x93.png 424w, https://substackcdn.com/image/fetch/$s_!Viv9!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4239d98e-0aff-450f-8416-d8189fb442bf_822x93.png 848w, https://substackcdn.com/image/fetch/$s_!Viv9!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4239d98e-0aff-450f-8416-d8189fb442bf_822x93.png 1272w, https://substackcdn.com/image/fetch/$s_!Viv9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4239d98e-0aff-450f-8416-d8189fb442bf_822x93.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><ul><li><p>This careful orchestration by the shell, <code>sudo</code>, and the kernel highlights Linux&#8217;s robust approach to process management and security. Understanding these details provides clarity on how Linux balances functionality with protection.</p></li></ul><div class="embedded-post-wrap" data-attrs="{&quot;id&quot;:152311675,&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/p/programs-and-process-in-linux-3&quot;,&quot;publication_id&quot;:3043184,&quot;publication_name&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd74e8425-0a13-40ad-86b5-27bdf5afe57f_800x800.png&quot;,&quot;title&quot;:&quot;Programs and Process in Linux - 3&quot;,&quot;truncated_body_text&quot;:&quot;How the Linux Kernel Manages Multiple Processes&quot;,&quot;date&quot;:&quot;2024-11-29T07:47:39.677Z&quot;,&quot;like_count&quot;:0,&quot;comment_count&quot;:0,&quot;bylines&quot;:[{&quot;id&quot;:114001497,&quot;name&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;handle&quot;:&quot;gopakumarrajappan&quot;,&quot;previous_name&quot;:null,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e0e7bbb2-d0a8-45af-9002-89ad7c317651_800x800.jpeg&quot;,&quot;bio&quot;:&quot;Programming, Computer Networks, Distributed systems&quot;,&quot;profile_set_up_at&quot;:&quot;2024-09-19T19:51:04.852Z&quot;,&quot;publicationUsers&quot;:[{&quot;id&quot;:3096759,&quot;user_id&quot;:114001497,&quot;publication_id&quot;:3043184,&quot;role&quot;:&quot;admin&quot;,&quot;public&quot;:true,&quot;is_primary&quot;:false,&quot;publication&quot;:{&quot;id&quot;:3043184,&quot;name&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;subdomain&quot;:&quot;gopakumarrajappan&quot;,&quot;custom_domain&quot;:&quot;www.gopakumar-rajappan.com&quot;,&quot;custom_domain_optional&quot;:false,&quot;hero_text&quot;:&quot;First Principles: A Guiding Path to Understanding Tech Advancements&quot;,&quot;logo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d74e8425-0a13-40ad-86b5-27bdf5afe57f_800x800.png&quot;,&quot;author_id&quot;:114001497,&quot;theme_var_background_pop&quot;:&quot;#FF6719&quot;,&quot;created_at&quot;:&quot;2024-09-19T19:51:30.712Z&quot;,&quot;rss_website_url&quot;:null,&quot;email_from_name&quot;:null,&quot;copyright&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;founding_plan_name&quot;:null,&quot;community_enabled&quot;:true,&quot;invite_only&quot;:false,&quot;payments_state&quot;:&quot;enabled&quot;,&quot;language&quot;:null,&quot;explicit&quot;:false,&quot;is_personal_mode&quot;:false}}],&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;utm_campaign&quot;:null,&quot;belowTheFold&quot;:true,&quot;type&quot;:&quot;newsletter&quot;,&quot;language&quot;:&quot;en&quot;,&quot;source&quot;:null}" data-component-name="EmbeddedPostToDOM"><a class="embedded-post" native="true" href="https://www.gopakumar-rajappan.com/p/programs-and-process-in-linux-3?utm_source=substack&amp;utm_campaign=post_embed&amp;utm_medium=web"><div class="embedded-post-header"><img class="embedded-post-publication-logo" src="https://substackcdn.com/image/fetch/$s_!0BMm!,w_56,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd74e8425-0a13-40ad-86b5-27bdf5afe57f_800x800.png" loading="lazy"><span class="embedded-post-publication-name">GOPAKUMAR RAJAPPAN</span></div><div class="embedded-post-title-wrapper"><div class="embedded-post-title">Programs and Process in Linux - 3</div></div><div class="embedded-post-body">How the Linux Kernel Manages Multiple Processes&#8230;</div><div class="embedded-post-cta-wrapper"><span class="embedded-post-cta">Read more</span></div><div class="embedded-post-meta">a year ago &#183; GOPAKUMAR RAJAPPAN</div></a></div><p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">GOPAKUMAR RAJAPPAN is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Programs and Processes in Linux - 1]]></title><description><![CDATA[When you execute a command like ls or sudo ls in a Linux shell, it triggers a fascinating transformation.]]></description><link>https://www.gopakumar-rajappan.com/p/programs-and-processes-in-linux-1</link><guid isPermaLink="false">https://www.gopakumar-rajappan.com/p/programs-and-processes-in-linux-1</guid><dc:creator><![CDATA[GOPAKUMAR RAJAPPAN]]></dc:creator><pubDate>Fri, 29 Nov 2024 07:00:06 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!3l2R!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b073631-3c12-401c-842a-7a2b63060c33_1024x1024.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!3l2R!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b073631-3c12-401c-842a-7a2b63060c33_1024x1024.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!3l2R!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b073631-3c12-401c-842a-7a2b63060c33_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!3l2R!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b073631-3c12-401c-842a-7a2b63060c33_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!3l2R!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b073631-3c12-401c-842a-7a2b63060c33_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!3l2R!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b073631-3c12-401c-842a-7a2b63060c33_1024x1024.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!3l2R!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b073631-3c12-401c-842a-7a2b63060c33_1024x1024.webp" width="1024" height="1024" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4b073631-3c12-401c-842a-7a2b63060c33_1024x1024.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:367594,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/webp&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!3l2R!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b073631-3c12-401c-842a-7a2b63060c33_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!3l2R!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b073631-3c12-401c-842a-7a2b63060c33_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!3l2R!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b073631-3c12-401c-842a-7a2b63060c33_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!3l2R!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b073631-3c12-401c-842a-7a2b63060c33_1024x1024.webp 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>When you execute a command like <code>ls</code> or <code>sudo ls</code> in a Linux shell, it triggers a fascinating transformation. A <strong>program</strong>, which is simply a static collection of instructions created by developers or code generators, transitions into a <strong>process</strong>, a dynamic entity managed by the operating system. While the program exists as a file in the filesystem, designed with a human-centric perspective, the <strong>process</strong> shifts that perspective to the <strong>kernel</strong>, which manages its lifecycle, resources, and interactions with the system.</p><p>The Linux kernel, the heart of the operating system, takes over as soon as a program becomes a process. It handles process creation, assigns resources, manages permissions, schedules execution, and ensures a seamless interaction between the process and system resources. This blog breaks down the entire journey&#8212;from program to process&#8212;exploring how the kernel orchestrates these operations. Along the way, we&#8217;ll delve into the key concepts of <strong>fork</strong>, <strong>exec</strong>, and the <strong>execution environment</strong>, unraveling the inner workings of Linux when commands are executed.</p><h3><strong>What Happens When You Run </strong><code>ls</code><strong> in the Shell?</strong></h3><h4><strong>The Shell as a Process</strong></h4><p>The shell (e.g., <code>bash</code>, <code>zsh</code>) is a command-line interface where you interact with the Linux operating system. It is itself a running process managed by the kernel, identified by a unique Process ID (<strong>PID</strong>).</p><ul><li><p>When you type a command like <code>ls</code>, the shell:</p><ul><li><p>Parses your input.</p></li><li><p>Searches for the <code>ls</code> program in the directories listed in the <code>$PATH</code> environment variable.</p></li><li><p>Prepares to execute the program by creating a new process.</p></li></ul></li></ul><h4><strong>Fork and Exec: Creating a New Process</strong></h4><p>To execute <code>ls</code>, the shell uses two critical system calls: <code>fork()</code> and <code>execve()</code>. A <strong>system call</strong> is a mechanism that allows a program to request services or resources from the operating system's kernel.</p><ol><li><p><code>fork()</code><strong>: Duplicating the Shell Process</strong></p><ul><li><p><strong>What is </strong><code>fork()</code><strong>?</strong></p><ul><li><p><code>fork()</code> is a system call that creates a new process by duplicating the current (parent) process.</p></li><li><p>The new process is called the <strong>child process</strong>, and it inherits the parent&#8217;s execution environment.</p></li></ul></li><li><p><strong>What Happens During </strong><code>fork()</code><strong>?</strong></p><ul><li><p>The kernel allocates a new PID for the child process.</p></li><li><p>The child process receives a copy of the parent&#8217;s:</p><ul><li><p><strong>Memory space</strong>: Code, data, and stack.</p></li><li><p><strong>File descriptors</strong>: Open files or sockets are shared.</p></li><li><p><strong>Environment variables</strong>: Copies variables like <code>$PATH</code>, <code>$HOME</code>, and <code>$USER</code>.</p></li><li><p><strong>Permissions</strong>: The child process inherits the parent&#8217;s user ID (UID) and group ID (GID).</p></li></ul></li></ul></li><li><p><strong>Why Use </strong><code>fork()</code><strong>?</strong></p><ul><li><p><code>fork()</code> enables the system to efficiently create new processes without starting from scratch. This is faster and preserves the parent's context.</p></li></ul><p></p><p><strong>Example</strong>: When the shell runs <code>ls</code>, it forks a child process that will execute the command.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!qyC5!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74e2a74a-b7cf-4aec-b5e2-f75384346f36_685x293.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!qyC5!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74e2a74a-b7cf-4aec-b5e2-f75384346f36_685x293.png 424w, https://substackcdn.com/image/fetch/$s_!qyC5!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74e2a74a-b7cf-4aec-b5e2-f75384346f36_685x293.png 848w, https://substackcdn.com/image/fetch/$s_!qyC5!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74e2a74a-b7cf-4aec-b5e2-f75384346f36_685x293.png 1272w, https://substackcdn.com/image/fetch/$s_!qyC5!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74e2a74a-b7cf-4aec-b5e2-f75384346f36_685x293.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!qyC5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74e2a74a-b7cf-4aec-b5e2-f75384346f36_685x293.png" width="685" height="293" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/74e2a74a-b7cf-4aec-b5e2-f75384346f36_685x293.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:293,&quot;width&quot;:685,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:12521,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!qyC5!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74e2a74a-b7cf-4aec-b5e2-f75384346f36_685x293.png 424w, https://substackcdn.com/image/fetch/$s_!qyC5!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74e2a74a-b7cf-4aec-b5e2-f75384346f36_685x293.png 848w, https://substackcdn.com/image/fetch/$s_!qyC5!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74e2a74a-b7cf-4aec-b5e2-f75384346f36_685x293.png 1272w, https://substackcdn.com/image/fetch/$s_!qyC5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74e2a74a-b7cf-4aec-b5e2-f75384346f36_685x293.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p></li><li><p><code>execve()</code><strong>: Replacing the Child Process</strong></p><ul><li><p><strong>What is </strong><code>execve()</code><strong>?</strong></p><ul><li><p><code>execve()</code> is a system call that replaces the current process's memory space with a new program.</p></li><li><p>The process retains its PID but replaces its code and data with those of the program being executed (<code>ls</code> in this case).</p></li></ul></li><li><p><strong>What Happens During </strong><code>execve()</code><strong>?</strong></p><ul><li><p>The <code>ls</code> program's binary is loaded into memory.</p></li><li><p>The child process starts executing <code>ls</code>, but its environment (e.g., open file descriptors, environment variables) remains intact.</p></li></ul></li><li><p><strong>Why Use </strong><code>execve()</code><strong>?</strong></p><ul><li><p><code>execve()</code> allows the child process to seamlessly transition to executing the desired program, leaving behind the parent's shell context.</p></li></ul></li><li><p><strong>Example</strong>: After the shell forks a child process, the child replaces its code with the <code>ls</code> program using <code>execve()</code>.</p></li></ul></li></ul><div><hr></div></li></ol><h4><strong>Execution Environment</strong></h4><p>The <strong>execution environment</strong> of a process is a set of attributes and resources that define its operating context. The child process created by <code>fork()</code> inherits its parent&#8217;s environment, which includes:</p><ol><li><p><strong>Environment Variables</strong>:</p><ul><li><p>Variables such as <code>$PATH</code>, <code>$HOME</code>, and <code>$USER</code> are inherited from the parent.</p></li><li><p>These variables provide essential configuration for the program. For example, <code>$PATH</code> determines where the system searches for executable files.</p></li></ul></li><li><p><strong>Open File Descriptors</strong>:</p><ul><li><p>File descriptors for any files, sockets, or pipes opened by the parent are inherited by the child.</p></li><li><p>This allows child processes to reuse or interact with resources already opened by the parent.</p></li></ul></li><li><p><strong>Permissions and Privileges</strong>:</p><ul><li><p>The child process inherits the user ID (UID) and group ID (GID) of the parent.</p></li><li><p>For commands like <code>ls</code>, this determines which files and directories the process can access.</p></li></ul></li></ol><div><hr></div><h4><strong>Kernel Scheduling</strong></h4><p>Once the <code>ls</code> process is created, the kernel takes over:</p><ul><li><p><strong>Process Scheduling</strong>:</p><ul><li><p>The kernel&#8217;s scheduler assigns CPU time to the <code>ls</code> process based on its priority and scheduling policies.</p></li><li><p>While the <code>ls</code> process is running, the parent shell process is typically put into a waiting state.</p></li></ul></li><li><p><strong>Completion</strong>:</p><ul><li><p>Once <code>ls</code> finishes execution, it sends an <strong>exit signal</strong> to the parent (shell) and terminates.</p></li><li><p>The kernel reclaims the resources allocated to the process.</p></li></ul></li></ul><div class="embedded-post-wrap" data-attrs="{&quot;id&quot;:152311407,&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/p/programs-and-processes-in-linux-2&quot;,&quot;publication_id&quot;:3043184,&quot;publication_name&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd74e8425-0a13-40ad-86b5-27bdf5afe57f_800x800.png&quot;,&quot;title&quot;:&quot;Programs and Processes in Linux - 2&quot;,&quot;truncated_body_text&quot;:&quot;What Happens When You Run sudo ls?&quot;,&quot;date&quot;:&quot;2024-11-29T07:03:25.605Z&quot;,&quot;like_count&quot;:0,&quot;comment_count&quot;:0,&quot;bylines&quot;:[{&quot;id&quot;:114001497,&quot;name&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;handle&quot;:&quot;gopakumarrajappan&quot;,&quot;previous_name&quot;:null,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e0e7bbb2-d0a8-45af-9002-89ad7c317651_800x800.jpeg&quot;,&quot;bio&quot;:&quot;Programming, Computer Networks, Distributed systems&quot;,&quot;profile_set_up_at&quot;:&quot;2024-09-19T19:51:04.852Z&quot;,&quot;publicationUsers&quot;:[{&quot;id&quot;:3096759,&quot;user_id&quot;:114001497,&quot;publication_id&quot;:3043184,&quot;role&quot;:&quot;admin&quot;,&quot;public&quot;:true,&quot;is_primary&quot;:false,&quot;publication&quot;:{&quot;id&quot;:3043184,&quot;name&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;subdomain&quot;:&quot;gopakumarrajappan&quot;,&quot;custom_domain&quot;:&quot;www.gopakumar-rajappan.com&quot;,&quot;custom_domain_optional&quot;:false,&quot;hero_text&quot;:&quot;First Principles: A Guiding Path to Understanding Tech Advancements&quot;,&quot;logo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d74e8425-0a13-40ad-86b5-27bdf5afe57f_800x800.png&quot;,&quot;author_id&quot;:114001497,&quot;theme_var_background_pop&quot;:&quot;#FF6719&quot;,&quot;created_at&quot;:&quot;2024-09-19T19:51:30.712Z&quot;,&quot;rss_website_url&quot;:null,&quot;email_from_name&quot;:null,&quot;copyright&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;founding_plan_name&quot;:null,&quot;community_enabled&quot;:true,&quot;invite_only&quot;:false,&quot;payments_state&quot;:&quot;enabled&quot;,&quot;language&quot;:null,&quot;explicit&quot;:false,&quot;is_personal_mode&quot;:false}}],&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;utm_campaign&quot;:null,&quot;belowTheFold&quot;:true,&quot;type&quot;:&quot;newsletter&quot;,&quot;language&quot;:&quot;en&quot;,&quot;source&quot;:null}" data-component-name="EmbeddedPostToDOM"><a class="embedded-post" native="true" href="https://www.gopakumar-rajappan.com/p/programs-and-processes-in-linux-2?utm_source=substack&amp;utm_campaign=post_embed&amp;utm_medium=web"><div class="embedded-post-header"><img class="embedded-post-publication-logo" src="https://substackcdn.com/image/fetch/$s_!0BMm!,w_56,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd74e8425-0a13-40ad-86b5-27bdf5afe57f_800x800.png" loading="lazy"><span class="embedded-post-publication-name">GOPAKUMAR RAJAPPAN</span></div><div class="embedded-post-title-wrapper"><div class="embedded-post-title">Programs and Processes in Linux - 2</div></div><div class="embedded-post-body">What Happens When You Run sudo ls&#8230;</div><div class="embedded-post-cta-wrapper"><span class="embedded-post-cta">Read more</span></div><div class="embedded-post-meta">a year ago &#183; GOPAKUMAR RAJAPPAN</div></a></div><p></p>]]></content:encoded></item><item><title><![CDATA[Mastering systemd: Managing Your Linux System with Ease]]></title><description><![CDATA[Linux systems rely on systemd, a modern and powerful initialization and service management tool, to handle services, processes, and system states.]]></description><link>https://www.gopakumar-rajappan.com/p/mastering-systemd-managing-your-linux</link><guid isPermaLink="false">https://www.gopakumar-rajappan.com/p/mastering-systemd-managing-your-linux</guid><dc:creator><![CDATA[GOPAKUMAR RAJAPPAN]]></dc:creator><pubDate>Fri, 29 Nov 2024 04:15:38 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!qfPe!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbba8a558-0b4d-49da-9610-aae5d6139d7a_1024x1024.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!qfPe!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbba8a558-0b4d-49da-9610-aae5d6139d7a_1024x1024.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!qfPe!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbba8a558-0b4d-49da-9610-aae5d6139d7a_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!qfPe!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbba8a558-0b4d-49da-9610-aae5d6139d7a_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!qfPe!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbba8a558-0b4d-49da-9610-aae5d6139d7a_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!qfPe!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbba8a558-0b4d-49da-9610-aae5d6139d7a_1024x1024.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!qfPe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbba8a558-0b4d-49da-9610-aae5d6139d7a_1024x1024.webp" width="1024" height="1024" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bba8a558-0b4d-49da-9610-aae5d6139d7a_1024x1024.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:425556,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/webp&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!qfPe!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbba8a558-0b4d-49da-9610-aae5d6139d7a_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!qfPe!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbba8a558-0b4d-49da-9610-aae5d6139d7a_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!qfPe!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbba8a558-0b4d-49da-9610-aae5d6139d7a_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!qfPe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbba8a558-0b4d-49da-9610-aae5d6139d7a_1024x1024.webp 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>Linux systems rely on <code>systemd</code>, a modern and powerful initialization and service management tool, to handle services, processes, and system states. Replacing traditional <code>init</code>, <code>systemd</code> offers efficiency, parallelism, and flexibility, making it the backbone of most Linux distributions today.</p><p>One of the standout features of <code>systemd</code> is its use of <strong>targets</strong>. Targets represent specific system states, such as multi-user mode or graphical mode, and replace the older runlevel concept. For instance, <code>multi-user.target</code> corresponds to a non-graphical multi-user environment, while <code>graphical.target</code> represents a system running with a GUI. This flexibility allows you to control and switch between different operating modes seamlessly.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">GOPAKUMAR RAJAPPAN is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>A single command, <code>systemctl</code>, is your gateway to managing services, targets, and system logs. Below, we&#8217;ll walk through examples of how to use <code>systemd</code> to control your Linux system effectively.</p><h3><strong>Using </strong><code>systemd</code><strong> to Manage Services</strong></h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!6ioD!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e652080-7061-4a35-b649-f51ad89dcc8e_1331x615.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!6ioD!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e652080-7061-4a35-b649-f51ad89dcc8e_1331x615.png 424w, https://substackcdn.com/image/fetch/$s_!6ioD!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e652080-7061-4a35-b649-f51ad89dcc8e_1331x615.png 848w, https://substackcdn.com/image/fetch/$s_!6ioD!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e652080-7061-4a35-b649-f51ad89dcc8e_1331x615.png 1272w, https://substackcdn.com/image/fetch/$s_!6ioD!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e652080-7061-4a35-b649-f51ad89dcc8e_1331x615.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!6ioD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e652080-7061-4a35-b649-f51ad89dcc8e_1331x615.png" width="1331" height="615" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4e652080-7061-4a35-b649-f51ad89dcc8e_1331x615.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:615,&quot;width&quot;:1331,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:122284,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!6ioD!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e652080-7061-4a35-b649-f51ad89dcc8e_1331x615.png 424w, https://substackcdn.com/image/fetch/$s_!6ioD!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e652080-7061-4a35-b649-f51ad89dcc8e_1331x615.png 848w, https://substackcdn.com/image/fetch/$s_!6ioD!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e652080-7061-4a35-b649-f51ad89dcc8e_1331x615.png 1272w, https://substackcdn.com/image/fetch/$s_!6ioD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e652080-7061-4a35-b649-f51ad89dcc8e_1331x615.png 1456w" sizes="100vw"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><div class="embedded-post-wrap" data-attrs="{&quot;id&quot;:152280744,&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/p/understanding-linux-file-systems&quot;,&quot;publication_id&quot;:3043184,&quot;publication_name&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd74e8425-0a13-40ad-86b5-27bdf5afe57f_800x800.png&quot;,&quot;title&quot;:&quot;Understanding Linux File Systems and Directory Structure - 1&quot;,&quot;truncated_body_text&quot;:&quot;The Linux file system is at the heart of the operating system, providing a structured way to store and access data. Rooted in Unix traditions, it organizes files and directories hierarchically, making Linux systems versatile and efficient.&quot;,&quot;date&quot;:&quot;2024-11-28T11:56:26.544Z&quot;,&quot;like_count&quot;:0,&quot;comment_count&quot;:0,&quot;bylines&quot;:[{&quot;id&quot;:114001497,&quot;name&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;handle&quot;:&quot;gopakumarrajappan&quot;,&quot;previous_name&quot;:null,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e0e7bbb2-d0a8-45af-9002-89ad7c317651_800x800.jpeg&quot;,&quot;bio&quot;:&quot;Programming, Computer Networks, Distributed systems&quot;,&quot;profile_set_up_at&quot;:&quot;2024-09-19T19:51:04.852Z&quot;,&quot;publicationUsers&quot;:[{&quot;id&quot;:3096759,&quot;user_id&quot;:114001497,&quot;publication_id&quot;:3043184,&quot;role&quot;:&quot;admin&quot;,&quot;public&quot;:true,&quot;is_primary&quot;:false,&quot;publication&quot;:{&quot;id&quot;:3043184,&quot;name&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;subdomain&quot;:&quot;gopakumarrajappan&quot;,&quot;custom_domain&quot;:&quot;www.gopakumar-rajappan.com&quot;,&quot;custom_domain_optional&quot;:false,&quot;hero_text&quot;:&quot;First Principles: A Guiding Path to Understanding Tech Advancements&quot;,&quot;logo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d74e8425-0a13-40ad-86b5-27bdf5afe57f_800x800.png&quot;,&quot;author_id&quot;:114001497,&quot;theme_var_background_pop&quot;:&quot;#FF6719&quot;,&quot;created_at&quot;:&quot;2024-09-19T19:51:30.712Z&quot;,&quot;rss_website_url&quot;:null,&quot;email_from_name&quot;:null,&quot;copyright&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;founding_plan_name&quot;:null,&quot;community_enabled&quot;:true,&quot;invite_only&quot;:false,&quot;payments_state&quot;:&quot;enabled&quot;,&quot;language&quot;:null,&quot;explicit&quot;:false,&quot;is_personal_mode&quot;:false}}],&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;utm_campaign&quot;:null,&quot;belowTheFold&quot;:true,&quot;type&quot;:&quot;newsletter&quot;,&quot;language&quot;:&quot;en&quot;,&quot;source&quot;:null}" data-component-name="EmbeddedPostToDOM"><a class="embedded-post" native="true" href="https://www.gopakumar-rajappan.com/p/understanding-linux-file-systems?utm_source=substack&amp;utm_campaign=post_embed&amp;utm_medium=web"><div class="embedded-post-header"><img class="embedded-post-publication-logo" src="https://substackcdn.com/image/fetch/$s_!0BMm!,w_56,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd74e8425-0a13-40ad-86b5-27bdf5afe57f_800x800.png" loading="lazy"><span class="embedded-post-publication-name">GOPAKUMAR RAJAPPAN</span></div><div class="embedded-post-title-wrapper"><div class="embedded-post-title">Understanding Linux File Systems and Directory Structure - 1</div></div><div class="embedded-post-body">The Linux file system is at the heart of the operating system, providing a structured way to store and access data. Rooted in Unix traditions, it organizes files and directories hierarchically, making Linux systems versatile and efficient&#8230;</div><div class="embedded-post-cta-wrapper"><span class="embedded-post-cta">Read more</span></div><div class="embedded-post-meta">a year ago &#183; GOPAKUMAR RAJAPPAN</div></a></div><h4></h4><p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">GOPAKUMAR RAJAPPAN is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Understanding PID 1: The Journey from init to systemd]]></title><description><![CDATA[When you power up a Linux system, a fascinating sequence of events unfolds behind the scenes.]]></description><link>https://www.gopakumar-rajappan.com/p/understanding-pid-1-the-journey-from</link><guid isPermaLink="false">https://www.gopakumar-rajappan.com/p/understanding-pid-1-the-journey-from</guid><dc:creator><![CDATA[GOPAKUMAR RAJAPPAN]]></dc:creator><pubDate>Fri, 29 Nov 2024 03:47:04 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!NxYM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F544d41dc-b970-4124-93c3-5b7ce04e0f8f_1024x1024.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!NxYM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F544d41dc-b970-4124-93c3-5b7ce04e0f8f_1024x1024.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!NxYM!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F544d41dc-b970-4124-93c3-5b7ce04e0f8f_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!NxYM!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F544d41dc-b970-4124-93c3-5b7ce04e0f8f_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!NxYM!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F544d41dc-b970-4124-93c3-5b7ce04e0f8f_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!NxYM!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F544d41dc-b970-4124-93c3-5b7ce04e0f8f_1024x1024.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!NxYM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F544d41dc-b970-4124-93c3-5b7ce04e0f8f_1024x1024.webp" width="1024" height="1024" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/544d41dc-b970-4124-93c3-5b7ce04e0f8f_1024x1024.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:320180,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/webp&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!NxYM!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F544d41dc-b970-4124-93c3-5b7ce04e0f8f_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!NxYM!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F544d41dc-b970-4124-93c3-5b7ce04e0f8f_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!NxYM!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F544d41dc-b970-4124-93c3-5b7ce04e0f8f_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!NxYM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F544d41dc-b970-4124-93c3-5b7ce04e0f8f_1024x1024.webp 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>When you power up a Linux system, a fascinating sequence of events unfolds behind the scenes. After the kernel loads into memory, it starts the very first process, known as <strong>PID 1</strong>. This process is the initialization system that brings the user space to life, orchestrating all other processes that make your system functional. But what exactly is PID 1, and how has it evolved over time?</p><h3><em><strong>Understanding Processes, Services, daemons</strong></em></h3><p><em>Before diving into PID 1, it's essential to understand what a <strong>process</strong> is in the context of an operating system. A process is an instance of a program in execution. It utilizes system resources like CPU time and memory to perform tasks. Every running application or service on your system is a process, each assigned a unique Process ID (PID) by the kernel.</em></p><p><em>A <strong>Service </strong>is a process running in the background<strong>, </strong>but not all background processes are considered services. A <strong>service</strong> is a background process designed for system-level functionality, managed by a service manager, and capable of operating independently and persistently. If a process is unmanaged, transient, or tied to a user session, it remains just a generic background process. For instance, if you install nginx webserver, it will be installed as a service and hence you will be able to manage it using &#8220;systemctl&#8221; commands of the systemd service manager</em></p><p><em>A <strong>daemon</strong> is a specific type of background process. It typically runs continuously, performing system-related tasks or waiting to respond to specific requests. Most services are implemented as daemons, but daemons have unique characteristics.</em></p><p><em>We will discuss process, services and daemons in detail in upcoming posts.</em><br></p><h3><strong>The Birth of </strong><code>init</code><strong>: The Original PID 1</strong></h3><p>In the early days of Unix and Linux, the <code>init</code> system was the default initialization process. As the first process started by the kernel (hence PID 1), <code>init</code> had the crucial role of bootstrapping the user space and managing system processes.</p><h4><strong>How </strong><code>init</code><strong> Worked</strong></h4><p><code>init</code> operated based on predefined configurations found in the <code>/etc/inittab</code> file. This file determined the system's <strong>runlevel</strong>, which defined the state of the machine and which services should be running.</p><ul><li><p><strong>Runlevels</strong>: Numeric codes representing different modes of operation. Common runlevels included:</p><ul><li><p><strong>0</strong>: Halt the system.</p></li><li><p><strong>1</strong>: Single-user mode for administrative tasks.</p></li><li><p><strong>2-5</strong>: Multi-user modes with various configurations.</p></li><li><p><strong>6</strong>: Reboot the system.</p></li></ul></li></ul><p>For example, runlevel 3 typically started the system in a multi-user, command-line mode, while runlevel 5 started the system with a graphical interface.</p><p><code>init</code> would execute scripts located in directories like <code>/etc/rc.d/</code> or <code>/etc/init.d/</code> corresponding to the selected runlevel, starting and stopping services in a sequential manner.</p><h4><strong>Drawbacks of </strong><code>init</code></h4><p>While revolutionary at its inception, <code>init</code> had several limitations:</p><ul><li><p><strong>Sequential Execution</strong>: Services started one after another, leading to longer boot times.</p></li><li><p><strong>No Dependency Handling</strong>: <code>init</code> didn't account for service dependencies, potentially causing issues if a service started before another service it relied on.</p></li><li><p><strong>Static Configuration</strong>: Adapting to dynamic hardware changes or new services required manual intervention.</p></li><li><p><strong>Limited Error Handling</strong>: If a service failed to start, <code>init</code> lacked robust mechanisms to handle or recover from the failure.</p></li></ul><h3><strong>The Transition to </strong><code>Upstart</code></h3><p>To address these challenges, the <code>Upstart</code> initialization system was introduced by the Ubuntu project. Upstart was designed to be event-driven, allowing the system to respond dynamically to events such as hardware changes or service status updates.</p><h4><strong>Features of </strong><code>Upstart</code></h4><ul><li><p><strong>Parallel Service Startup</strong>: Enabled services to start simultaneously where possible, reducing boot times.</p></li><li><p><strong>Event-Driven Architecture</strong>: Services could start or stop in response to specific events, improving flexibility.</p></li><li><p><strong>Backward Compatibility</strong>: Maintained support for traditional <code>init</code> scripts, easing the transition.</p></li></ul><p>Despite its innovations, Upstart faced adoption challenges outside of Ubuntu and introduced complexities in managing event handling.</p><h3><strong>Enter </strong><code>systemd</code><strong>: The Modern Initialization System</strong></h3><p>Recognizing the need for a more robust and unified solution, developers introduced <code>systemd</code>, which has since become the standard initialization system for most Linux distributions.</p><h4><strong>What Makes </strong><code>systemd</code><strong> Different?</strong></h4><ul><li><p><strong>Parallelization Capabilities</strong>: Aggressively starts services in parallel, significantly reducing boot times.</p></li><li><p><strong>Dependency Management</strong>: Understands and manages service dependencies, ensuring they start and stop in the correct order.</p></li><li><p><strong>Socket and D-Bus Activation</strong>: Services can be started on-demand when their functionality is needed, optimizing resource usage.</p></li><li><p><strong>Unified Configuration with Units</strong>: Uses simple, standardized unit files for configuration, typically located in <code>/etc/systemd/system/</code>.</p></li><li><p><strong>Targets Instead of Runlevels</strong>: Replaces traditional runlevels with <strong>targets</strong>, which are more flexible and descriptive.</p></li></ul><h4><strong>Understanding Targets</strong></h4><p><strong>Targets</strong> in <code>systemd</code> serve a similar purpose to runlevels but offer greater flexibility. Some common targets include:</p><ul><li><p><code>multi-user.target</code>: Similar to runlevel 3, a multi-user, non-graphical mode.</p></li><li><p><code>graphical.target</code>: Similar to runlevel 5, starts the system with a graphical user interface.</p></li><li><p><code>rescue.target</code>: A single-user mode for system maintenance, akin to runlevel 1.</p></li></ul><h4><strong>Advantages of </strong><code>systemd</code></h4><ul><li><p><strong>Efficiency</strong>: Faster boot times due to concurrent service startup.</p></li><li><p><strong>Reliability</strong>: Improved handling of dependencies and robust service management.</p></li><li><p><strong>Extensibility</strong>: Modular design allows for additional functionalities like logging (<code>journald</code>) and device management (<code>udevd</code>).</p></li></ul><p>In the next post we will discuss the usage of systemd.</p><p>       </p><div class="embedded-post-wrap" data-attrs="{&quot;id&quot;:152308095,&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/p/mastering-systemd-managing-your-linux&quot;,&quot;publication_id&quot;:3043184,&quot;publication_name&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd74e8425-0a13-40ad-86b5-27bdf5afe57f_800x800.png&quot;,&quot;title&quot;:&quot;Mastering systemd: Managing Your Linux System with Ease&quot;,&quot;truncated_body_text&quot;:&quot;Linux systems rely on systemd, a modern and powerful initialization and service management tool, to handle services, processes, and system states. Replacing traditional init, systemd offers efficiency, parallelism, and flexibility, making it the backbone of most Linux distributions today.&quot;,&quot;date&quot;:&quot;2024-11-29T04:15:38.655Z&quot;,&quot;like_count&quot;:0,&quot;comment_count&quot;:0,&quot;bylines&quot;:[{&quot;id&quot;:114001497,&quot;name&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;handle&quot;:&quot;gopakumarrajappan&quot;,&quot;previous_name&quot;:null,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e0e7bbb2-d0a8-45af-9002-89ad7c317651_800x800.jpeg&quot;,&quot;bio&quot;:&quot;Programming, Computer Networks, Distributed systems&quot;,&quot;profile_set_up_at&quot;:&quot;2024-09-19T19:51:04.852Z&quot;,&quot;publicationUsers&quot;:[{&quot;id&quot;:3096759,&quot;user_id&quot;:114001497,&quot;publication_id&quot;:3043184,&quot;role&quot;:&quot;admin&quot;,&quot;public&quot;:true,&quot;is_primary&quot;:false,&quot;publication&quot;:{&quot;id&quot;:3043184,&quot;name&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;subdomain&quot;:&quot;gopakumarrajappan&quot;,&quot;custom_domain&quot;:&quot;www.gopakumar-rajappan.com&quot;,&quot;custom_domain_optional&quot;:false,&quot;hero_text&quot;:&quot;First Principles: A Guiding Path to Understanding Tech Advancements&quot;,&quot;logo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d74e8425-0a13-40ad-86b5-27bdf5afe57f_800x800.png&quot;,&quot;author_id&quot;:114001497,&quot;theme_var_background_pop&quot;:&quot;#FF6719&quot;,&quot;created_at&quot;:&quot;2024-09-19T19:51:30.712Z&quot;,&quot;rss_website_url&quot;:null,&quot;email_from_name&quot;:null,&quot;copyright&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;founding_plan_name&quot;:null,&quot;community_enabled&quot;:true,&quot;invite_only&quot;:false,&quot;payments_state&quot;:&quot;enabled&quot;,&quot;language&quot;:null,&quot;explicit&quot;:false,&quot;is_personal_mode&quot;:false}}],&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;utm_campaign&quot;:null,&quot;belowTheFold&quot;:true,&quot;type&quot;:&quot;newsletter&quot;,&quot;language&quot;:&quot;en&quot;,&quot;source&quot;:null}" data-component-name="EmbeddedPostToDOM"><a class="embedded-post" native="true" href="https://www.gopakumar-rajappan.com/p/mastering-systemd-managing-your-linux?utm_source=substack&amp;utm_campaign=post_embed&amp;utm_medium=web"><div class="embedded-post-header"><img class="embedded-post-publication-logo" src="https://substackcdn.com/image/fetch/$s_!0BMm!,w_56,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd74e8425-0a13-40ad-86b5-27bdf5afe57f_800x800.png" loading="lazy"><span class="embedded-post-publication-name">GOPAKUMAR RAJAPPAN</span></div><div class="embedded-post-title-wrapper"><div class="embedded-post-title">Mastering systemd: Managing Your Linux System with Ease</div></div><div class="embedded-post-body">Linux systems rely on systemd, a modern and powerful initialization and service management tool, to handle services, processes, and system states. Replacing traditional init, systemd offers efficiency, parallelism, and flexibility, making it the backbone of most Linux distributions today&#8230;</div><div class="embedded-post-cta-wrapper"><span class="embedded-post-cta">Read more</span></div><div class="embedded-post-meta">a year ago &#183; GOPAKUMAR RAJAPPAN</div></a></div><p> </p>]]></content:encoded></item><item><title><![CDATA[Understanding the Bootloader: How Your Linux System Comes to Life]]></title><description><![CDATA[When you press the power button on your computer, a series of intricate steps unfolds to bring your operating system to life.]]></description><link>https://www.gopakumar-rajappan.com/p/understanding-the-bootloader-how</link><guid isPermaLink="false">https://www.gopakumar-rajappan.com/p/understanding-the-bootloader-how</guid><dc:creator><![CDATA[GOPAKUMAR RAJAPPAN]]></dc:creator><pubDate>Fri, 29 Nov 2024 02:58:21 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!fv12!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb07e3d1-77b0-46e6-904d-675b620837c2_1792x1024.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!fv12!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb07e3d1-77b0-46e6-904d-675b620837c2_1792x1024.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!fv12!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb07e3d1-77b0-46e6-904d-675b620837c2_1792x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!fv12!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb07e3d1-77b0-46e6-904d-675b620837c2_1792x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!fv12!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb07e3d1-77b0-46e6-904d-675b620837c2_1792x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!fv12!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb07e3d1-77b0-46e6-904d-675b620837c2_1792x1024.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!fv12!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb07e3d1-77b0-46e6-904d-675b620837c2_1792x1024.webp" width="1456" height="832" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/eb07e3d1-77b0-46e6-904d-675b620837c2_1792x1024.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:832,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:646200,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/webp&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!fv12!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb07e3d1-77b0-46e6-904d-675b620837c2_1792x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!fv12!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb07e3d1-77b0-46e6-904d-675b620837c2_1792x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!fv12!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb07e3d1-77b0-46e6-904d-675b620837c2_1792x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!fv12!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb07e3d1-77b0-46e6-904d-675b620837c2_1792x1024.webp 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>When you press the power button on your computer, a series of intricate steps unfolds to bring your operating system to life. At the heart of this process is the <strong>bootloader</strong>, a small yet essential program that acts as a bridge between your computer's firmware and the Linux operating system kernel. Let&#8217;s explore what a bootloader is, how it works, and why it&#8217;s crucial for your system.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">GOPAKUMAR RAJAPPAN is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><div><hr></div><h3><strong>What is a Bootloader?</strong></h3><p>A <strong>bootloader</strong> is a small program stored in a special section of your storage device, such as the Master Boot Record (MBR) or the GUID Partition Table (GPT). Its primary job is to load the operating system kernel into memory and hand over control to it. Without a bootloader, your computer wouldn&#8217;t know how to start the operating system.</p><div><hr></div><h3><strong>Why Do We Need a Bootloader?</strong></h3><ol><li><p><strong>Hardware Independence</strong>: The bootloader acts as a translator between the computer hardware and the operating system, ensuring compatibility across different devices.</p></li><li><p><strong>Multiple Operating Systems</strong>: It enables you to select between multiple operating systems, such as dual-booting Linux and Windows.</p></li><li><p><strong>Kernel Customization</strong>: It allows you to pass parameters to the kernel for debugging or specific configurations, such as booting into single-user mode.</p></li></ol><div><hr></div><h3><strong>How the Bootloader Works</strong></h3><p>Here&#8217;s a step-by-step overview of how a bootloader works to boot the operating system:</p><h4><strong>1. Power-On and Firmware Initialization</strong></h4><p>When you turn on your computer, the firmware (BIOS or UEFI) runs a <strong>Power-On Self Test (POST)</strong> to initialize and check hardware components like the keyboard, screen, and memory. Once POST is complete, the firmware identifies a bootable device and loads the bootloader into memory.</p><h4><strong>2. Bootloader Execution</strong></h4><ul><li><p><strong>In BIOS Systems (Using MBR)</strong>:</p><ul><li><p>The <strong>Master Boot Record (MBR)</strong>, located in the first 512 bytes of the storage device, contains a small piece of bootloader code and the partition table.</p></li><li><p>After the BIOS loads the MBR, the bootloader (e.g., GRUB or LILO) takes over and begins loading the operating system.</p></li></ul></li><li><p><strong>In UEFI Systems (Using ESP)</strong>:</p><ul><li><p>Modern systems replace MBR with the <strong>EFI System Partition (ESP)</strong>. This partition stores bootloader files and other essential data needed to boot the OS. The <strong>EFI System Partition (ESP)</strong> is a dedicated partition on storage devices used by UEFI systems. It simplifies the boot process by standardizing where bootloader and firmware-related files are stored.</p></li></ul></li></ul><h3><strong>3. Loading the Operating System</strong></h3><p>Once the bootloader is loaded, it proceeds with these steps:</p><ol><li><p><strong>Kernel Loading</strong>:<br>The bootloader locates the operating system kernel (e.g., <code>/boot/vmlinuz</code>) and loads it into memory. If necessary, it also loads an <strong><a href="https://www.gopakumar-rajappan.com/p/initial-ram-disk-initramfs-in-linux">initramfs</a></strong> (initial RAM filesystem) to help initialize hardware before the root filesystem is mounted.</p></li><li><p><strong>Passing Control to the Kernel</strong>:<br>The bootloader hands control to the kernel, along with any boot parameters (e.g., <code>root=/dev/sda1</code>). The kernel then initializes the system and starts the first process (<code>init</code> or <code>systemd</code>, known as PID 1).</p></li></ol><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!HjJz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fba918dc1-7c53-41a6-82b2-9bca1f858e77_897x612.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!HjJz!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fba918dc1-7c53-41a6-82b2-9bca1f858e77_897x612.png 424w, https://substackcdn.com/image/fetch/$s_!HjJz!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fba918dc1-7c53-41a6-82b2-9bca1f858e77_897x612.png 848w, https://substackcdn.com/image/fetch/$s_!HjJz!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fba918dc1-7c53-41a6-82b2-9bca1f858e77_897x612.png 1272w, https://substackcdn.com/image/fetch/$s_!HjJz!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fba918dc1-7c53-41a6-82b2-9bca1f858e77_897x612.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!HjJz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fba918dc1-7c53-41a6-82b2-9bca1f858e77_897x612.png" width="897" height="612" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ba918dc1-7c53-41a6-82b2-9bca1f858e77_897x612.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:612,&quot;width&quot;:897,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:35476,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!HjJz!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fba918dc1-7c53-41a6-82b2-9bca1f858e77_897x612.png 424w, https://substackcdn.com/image/fetch/$s_!HjJz!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fba918dc1-7c53-41a6-82b2-9bca1f858e77_897x612.png 848w, https://substackcdn.com/image/fetch/$s_!HjJz!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fba918dc1-7c53-41a6-82b2-9bca1f858e77_897x612.png 1272w, https://substackcdn.com/image/fetch/$s_!HjJz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fba918dc1-7c53-41a6-82b2-9bca1f858e77_897x612.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3><strong>Popular Bootloaders in Linux</strong></h3><p>Here are some of the most commonly used bootloaders:</p><ol><li><p><strong>GRUB (GNU GRUB)</strong>:</p><ul><li><p>The most widely used bootloader for Linux.</p></li><li><p>Supports multi-boot setups, graphical menus, and advanced configurations.</p></li><li><p>Configuration file: <code>/boot/grub/grub.cfg</code>.</p></li></ul></li><li><p><strong>LILO (Linux Loader)</strong>:</p><ul><li><p>An older bootloader, simple but limited compared to GRUB.</p></li><li><p>Rarely used today due to lack of modern features.</p></li></ul></li><li><p><strong>SYSLINUX/ISOLINUX</strong>:</p><ul><li><p>Lightweight bootloaders often used for live USBs or embedded systems.</p></li></ul></li><li><p><strong>systemd-boot</strong></p><ul><li><p>A modern bootloader designed to work seamlessly with UEFI systems.</p></li><li><p>Focuses on simplicity and integrates tightly with <code>systemd</code>.</p></li></ul></li></ol><div><hr></div><h3><strong>In Summary</strong></h3><p>The bootloader is the critical link between your computer&#8217;s firmware and the operating system. It initializes the kernel, enabling the OS to take control and start running. Whether you&#8217;re using BIOS with MBR or UEFI with ESP, the bootloader ensures a smooth handoff from hardware to software.</p><div class="embedded-post-wrap" data-attrs="{&quot;id&quot;:152307430,&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/p/understanding-pid-1-the-journey-from&quot;,&quot;publication_id&quot;:3043184,&quot;publication_name&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd74e8425-0a13-40ad-86b5-27bdf5afe57f_800x800.png&quot;,&quot;title&quot;:&quot;Understanding PID 1: The Journey from init to systemd&quot;,&quot;truncated_body_text&quot;:&quot;When you power up a Linux system, a fascinating sequence of events unfolds behind the scenes. After the kernel loads into memory, it starts the very first process, known as PID 1. This process is the initialization system that brings the user space to life, orchestrating all other processes that make your system functional. But what exactly is PID 1, an&#8230;&quot;,&quot;date&quot;:&quot;2024-11-29T03:47:04.980Z&quot;,&quot;like_count&quot;:0,&quot;comment_count&quot;:0,&quot;bylines&quot;:[{&quot;id&quot;:114001497,&quot;name&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;handle&quot;:&quot;gopakumarrajappan&quot;,&quot;previous_name&quot;:null,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e0e7bbb2-d0a8-45af-9002-89ad7c317651_800x800.jpeg&quot;,&quot;bio&quot;:&quot;Programming, Computer Networks, Distributed systems&quot;,&quot;profile_set_up_at&quot;:&quot;2024-09-19T19:51:04.852Z&quot;,&quot;publicationUsers&quot;:[{&quot;id&quot;:3096759,&quot;user_id&quot;:114001497,&quot;publication_id&quot;:3043184,&quot;role&quot;:&quot;admin&quot;,&quot;public&quot;:true,&quot;is_primary&quot;:false,&quot;publication&quot;:{&quot;id&quot;:3043184,&quot;name&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;subdomain&quot;:&quot;gopakumarrajappan&quot;,&quot;custom_domain&quot;:&quot;www.gopakumar-rajappan.com&quot;,&quot;custom_domain_optional&quot;:false,&quot;hero_text&quot;:&quot;First Principles: A Guiding Path to Understanding Tech Advancements&quot;,&quot;logo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d74e8425-0a13-40ad-86b5-27bdf5afe57f_800x800.png&quot;,&quot;author_id&quot;:114001497,&quot;theme_var_background_pop&quot;:&quot;#FF6719&quot;,&quot;created_at&quot;:&quot;2024-09-19T19:51:30.712Z&quot;,&quot;rss_website_url&quot;:null,&quot;email_from_name&quot;:null,&quot;copyright&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;founding_plan_name&quot;:null,&quot;community_enabled&quot;:true,&quot;invite_only&quot;:false,&quot;payments_state&quot;:&quot;enabled&quot;,&quot;language&quot;:null,&quot;explicit&quot;:false,&quot;is_personal_mode&quot;:false}}],&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;utm_campaign&quot;:null,&quot;belowTheFold&quot;:true,&quot;type&quot;:&quot;newsletter&quot;,&quot;language&quot;:&quot;en&quot;,&quot;source&quot;:null}" data-component-name="EmbeddedPostToDOM"><a class="embedded-post" native="true" href="https://www.gopakumar-rajappan.com/p/understanding-pid-1-the-journey-from?utm_source=substack&amp;utm_campaign=post_embed&amp;utm_medium=web"><div class="embedded-post-header"><img class="embedded-post-publication-logo" src="https://substackcdn.com/image/fetch/$s_!0BMm!,w_56,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd74e8425-0a13-40ad-86b5-27bdf5afe57f_800x800.png" loading="lazy"><span class="embedded-post-publication-name">GOPAKUMAR RAJAPPAN</span></div><div class="embedded-post-title-wrapper"><div class="embedded-post-title">Understanding PID 1: The Journey from init to systemd</div></div><div class="embedded-post-body">When you power up a Linux system, a fascinating sequence of events unfolds behind the scenes. After the kernel loads into memory, it starts the very first process, known as PID 1. This process is the initialization system that brings the user space to life, orchestrating all other processes that make your system functional. But what exactly is PID 1, an&#8230;</div><div class="embedded-post-cta-wrapper"><span class="embedded-post-cta">Read more</span></div><div class="embedded-post-meta">a year ago &#183; GOPAKUMAR RAJAPPAN</div></a></div><p></p><p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">GOPAKUMAR RAJAPPAN is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Understanding Linux File Systems and Directory Structure - 2]]></title><description><![CDATA[How Linux File Systems Work]]></description><link>https://www.gopakumar-rajappan.com/p/understanding-linux-file-systems-571</link><guid isPermaLink="false">https://www.gopakumar-rajappan.com/p/understanding-linux-file-systems-571</guid><dc:creator><![CDATA[GOPAKUMAR RAJAPPAN]]></dc:creator><pubDate>Thu, 28 Nov 2024 12:09:28 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!nIjM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F14fffd02-95f1-4424-8126-ec536adcfffe_1024x1024.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!nIjM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F14fffd02-95f1-4424-8126-ec536adcfffe_1024x1024.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!nIjM!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F14fffd02-95f1-4424-8126-ec536adcfffe_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!nIjM!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F14fffd02-95f1-4424-8126-ec536adcfffe_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!nIjM!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F14fffd02-95f1-4424-8126-ec536adcfffe_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!nIjM!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F14fffd02-95f1-4424-8126-ec536adcfffe_1024x1024.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!nIjM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F14fffd02-95f1-4424-8126-ec536adcfffe_1024x1024.webp" width="1024" height="1024" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/14fffd02-95f1-4424-8126-ec536adcfffe_1024x1024.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:163564,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/webp&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!nIjM!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F14fffd02-95f1-4424-8126-ec536adcfffe_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!nIjM!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F14fffd02-95f1-4424-8126-ec536adcfffe_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!nIjM!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F14fffd02-95f1-4424-8126-ec536adcfffe_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!nIjM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F14fffd02-95f1-4424-8126-ec536adcfffe_1024x1024.webp 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><h3><strong>How Linux File Systems Work</strong></h3><p>The Linux file system provides a logical structure, regardless of the underlying storage device. Directories are used to group related files, and paths (e.g., <code>/home/user/docs</code>) provide intuitive navigation. The kernel handles file operations through the Virtual File System (VFS), which abstracts the underlying file systems.</p><h3><strong>Understanding the Role of the Virtual File System (VFS) in Linux</strong></h3><p>The phrase "The kernel handles file operations through the Virtual File System (VFS), which abstracts the underlying file systems" describes how Linux provides a unified way to interact with files, no matter where or how they are stored. Let&#8217;s break it down step by step.</p><div><hr></div><h3><strong>What is the Virtual File System (VFS)?</strong></h3><p>The <strong>Virtual File System (VFS)</strong> is a layer within the Linux kernel that acts as a bridge between user applications and the various file systems supported by the operating system. It allows applications to access files uniformly, regardless of the specific file system or storage medium being used.</p><p>Think of VFS as a translator:</p><ul><li><p>To the user, every file and directory looks and behaves the same way.</p></li><li><p>Behind the scenes, the VFS translates these file operations into commands specific to the underlying file system (e.g., Ext4, XFS, NTFS).</p></li></ul><h3><strong>Why is VFS Important?</strong></h3><ol><li><p><strong>Uniformity</strong>: Users and applications interact with files and directories in the same way, even if they&#8217;re stored on different file systems or devices.</p><ul><li><p>Example: You can open, read, or write a file using the same commands, whether it&#8217;s on an Ext4 partition, an NTFS drive, or a remote file system like NFS.</p></li></ul></li><li><p><strong>Abstraction</strong>: By abstracting the details of individual file systems, the VFS makes it easier for the kernel to support multiple file systems without requiring applications to change their behavior.</p></li><li><p><strong>Flexibility</strong>: Linux can seamlessly handle a mix of file systems across local disks, remote servers, and virtual devices because of VFS.</p></li></ol><h3><strong>Linux Directory Hierarchy</strong></h3><p>The Linux directory structure starts from the <strong>root directory (</strong><code>/</code><strong>)</strong> and branches into subdirectories. Each has a specific purpose, ensuring consistency across distributions. Below are some of the directories in linux file system.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!onSt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc51ef587-bbf2-4bc2-8c42-a001371552a8_788x652.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!onSt!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc51ef587-bbf2-4bc2-8c42-a001371552a8_788x652.png 424w, https://substackcdn.com/image/fetch/$s_!onSt!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc51ef587-bbf2-4bc2-8c42-a001371552a8_788x652.png 848w, https://substackcdn.com/image/fetch/$s_!onSt!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc51ef587-bbf2-4bc2-8c42-a001371552a8_788x652.png 1272w, https://substackcdn.com/image/fetch/$s_!onSt!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc51ef587-bbf2-4bc2-8c42-a001371552a8_788x652.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!onSt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc51ef587-bbf2-4bc2-8c42-a001371552a8_788x652.png" width="788" height="652" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c51ef587-bbf2-4bc2-8c42-a001371552a8_788x652.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:652,&quot;width&quot;:788,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:74875,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!onSt!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc51ef587-bbf2-4bc2-8c42-a001371552a8_788x652.png 424w, https://substackcdn.com/image/fetch/$s_!onSt!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc51ef587-bbf2-4bc2-8c42-a001371552a8_788x652.png 848w, https://substackcdn.com/image/fetch/$s_!onSt!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc51ef587-bbf2-4bc2-8c42-a001371552a8_788x652.png 1272w, https://substackcdn.com/image/fetch/$s_!onSt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc51ef587-bbf2-4bc2-8c42-a001371552a8_788x652.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>More details about file system can be found at <a href="https://refspecs.linuxfoundation.org/FHS_3.0/fhs-3.0.pdf">File System Hierarchy Standard</a></p><div class="embedded-post-wrap" data-attrs="{&quot;id&quot;:152310872,&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/p/programs-and-processes-in-linux-1&quot;,&quot;publication_id&quot;:3043184,&quot;publication_name&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd74e8425-0a13-40ad-86b5-27bdf5afe57f_800x800.png&quot;,&quot;title&quot;:&quot;Programs and Processes in Linux - 1&quot;,&quot;truncated_body_text&quot;:&quot;When you execute a command like ls or sudo ls in a Linux shell, it triggers a fascinating transformation. A program, which is simply a static collection of instructions created by developers or code generators, transitions into a process, a dynamic entity managed by the operating system. While the program exists as a file in the filesystem, designed wit&#8230;&quot;,&quot;date&quot;:&quot;2024-11-29T07:00:06.863Z&quot;,&quot;like_count&quot;:0,&quot;comment_count&quot;:0,&quot;bylines&quot;:[{&quot;id&quot;:114001497,&quot;name&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;handle&quot;:&quot;gopakumarrajappan&quot;,&quot;previous_name&quot;:null,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e0e7bbb2-d0a8-45af-9002-89ad7c317651_800x800.jpeg&quot;,&quot;bio&quot;:&quot;Programming, Computer Networks, Distributed systems&quot;,&quot;profile_set_up_at&quot;:&quot;2024-09-19T19:51:04.852Z&quot;,&quot;publicationUsers&quot;:[{&quot;id&quot;:3096759,&quot;user_id&quot;:114001497,&quot;publication_id&quot;:3043184,&quot;role&quot;:&quot;admin&quot;,&quot;public&quot;:true,&quot;is_primary&quot;:false,&quot;publication&quot;:{&quot;id&quot;:3043184,&quot;name&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;subdomain&quot;:&quot;gopakumarrajappan&quot;,&quot;custom_domain&quot;:&quot;www.gopakumar-rajappan.com&quot;,&quot;custom_domain_optional&quot;:false,&quot;hero_text&quot;:&quot;First Principles: A Guiding Path to Understanding Tech Advancements&quot;,&quot;logo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d74e8425-0a13-40ad-86b5-27bdf5afe57f_800x800.png&quot;,&quot;author_id&quot;:114001497,&quot;theme_var_background_pop&quot;:&quot;#FF6719&quot;,&quot;created_at&quot;:&quot;2024-09-19T19:51:30.712Z&quot;,&quot;rss_website_url&quot;:null,&quot;email_from_name&quot;:null,&quot;copyright&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;founding_plan_name&quot;:null,&quot;community_enabled&quot;:true,&quot;invite_only&quot;:false,&quot;payments_state&quot;:&quot;enabled&quot;,&quot;language&quot;:null,&quot;explicit&quot;:false,&quot;is_personal_mode&quot;:false}}],&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;utm_campaign&quot;:null,&quot;belowTheFold&quot;:true,&quot;type&quot;:&quot;newsletter&quot;,&quot;language&quot;:&quot;en&quot;,&quot;source&quot;:null}" data-component-name="EmbeddedPostToDOM"><a class="embedded-post" native="true" href="https://www.gopakumar-rajappan.com/p/programs-and-processes-in-linux-1?utm_source=substack&amp;utm_campaign=post_embed&amp;utm_medium=web"><div class="embedded-post-header"><img class="embedded-post-publication-logo" src="https://substackcdn.com/image/fetch/$s_!0BMm!,w_56,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd74e8425-0a13-40ad-86b5-27bdf5afe57f_800x800.png" loading="lazy"><span class="embedded-post-publication-name">GOPAKUMAR RAJAPPAN</span></div><div class="embedded-post-title-wrapper"><div class="embedded-post-title">Programs and Processes in Linux - 1</div></div><div class="embedded-post-body">When you execute a command like ls or sudo ls in a Linux shell, it triggers a fascinating transformation. A program, which is simply a static collection of instructions created by developers or code generators, transitions into a process, a dynamic entity managed by the operating system. While the program exists as a file in the filesystem, designed wit&#8230;</div><div class="embedded-post-cta-wrapper"><span class="embedded-post-cta">Read more</span></div><div class="embedded-post-meta">a year ago &#183; GOPAKUMAR RAJAPPAN</div></a></div><p></p><p></p>]]></content:encoded></item><item><title><![CDATA[Understanding Linux File Systems and Directory Structure - 1]]></title><description><![CDATA[The Linux file system is at the heart of the operating system, providing a structured way to store and access data.]]></description><link>https://www.gopakumar-rajappan.com/p/understanding-linux-file-systems</link><guid isPermaLink="false">https://www.gopakumar-rajappan.com/p/understanding-linux-file-systems</guid><dc:creator><![CDATA[GOPAKUMAR RAJAPPAN]]></dc:creator><pubDate>Thu, 28 Nov 2024 11:56:26 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!D67a!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37d1e546-0e13-4f17-8ab4-6c1b24f537e0_1024x1024.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!D67a!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37d1e546-0e13-4f17-8ab4-6c1b24f537e0_1024x1024.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!D67a!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37d1e546-0e13-4f17-8ab4-6c1b24f537e0_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!D67a!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37d1e546-0e13-4f17-8ab4-6c1b24f537e0_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!D67a!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37d1e546-0e13-4f17-8ab4-6c1b24f537e0_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!D67a!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37d1e546-0e13-4f17-8ab4-6c1b24f537e0_1024x1024.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!D67a!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37d1e546-0e13-4f17-8ab4-6c1b24f537e0_1024x1024.webp" width="1024" height="1024" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/37d1e546-0e13-4f17-8ab4-6c1b24f537e0_1024x1024.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:163564,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/webp&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!D67a!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37d1e546-0e13-4f17-8ab4-6c1b24f537e0_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!D67a!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37d1e546-0e13-4f17-8ab4-6c1b24f537e0_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!D67a!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37d1e546-0e13-4f17-8ab4-6c1b24f537e0_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!D67a!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37d1e546-0e13-4f17-8ab4-6c1b24f537e0_1024x1024.webp 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>The Linux file system is at the heart of the operating system, providing a structured way to store and access data. Rooted in Unix traditions, it organizes files and directories hierarchically, making Linux systems versatile and efficient.</p><div><hr></div><h3><strong>Origins of Linux File Systems</strong></h3><p>The Linux file system's design stems from Unix, created in the 1970s to provide a simple, hierarchical way to organize files. Early Linux distributions adopted the <strong>Ext (Extended File System)</strong> in 1992, with subsequent improvements leading to modern file systems like <strong>Ext4</strong>, <strong>XFS</strong>, and <strong>Btrfs</strong>.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">GOPAKUMAR RAJAPPAN is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>In Linux, the phrase "everything is a file" reflects a core design philosophy inherited from Unix. This principle simplifies how the operating system interacts with various components, whether they are hardware devices, processes, or data. Let&#8217;s break it down:</p><div><hr></div><h4><strong>1. Uniform Interface</strong></h4><p>In Linux, everything&#8212;whether it&#8217;s hardware like a disk drive or software like a running process&#8212;is represented as a file. This uniformity means you interact with all these components using the same tools and commands, such as <code>cat</code>, <code>ls</code>, or <code>echo</code>.</p><ul><li><p><strong>Example</strong>: Reading data from a file on disk (<code>/home/user/document.txt</code>) uses the same commands as reading data from a hardware device (<code>/dev/sda</code>).</p></li></ul><div><hr></div><h4><strong>2. Hardware Devices as Files</strong></h4><p>Hardware devices in Linux are represented as <strong>device files</strong>, typically found in the <code>/dev</code> directory. These special files allow users and programs to communicate with hardware through simple file operations like reading and writing.</p><ul><li><p><strong>Example</strong>: <code>/dev/sda</code> represents a storage device. Writing to this file can directly modify the disk.</p></li></ul><div><hr></div><h4><strong>3. Processes as Files</strong></h4><p>Processes in Linux are represented in the <code>/proc</code> directory, which is a virtual file system. Each process has its own subdirectory (e.g., <code>/proc/123</code> for process ID 123), containing files that provide real-time information about the process, like its memory usage or command-line arguments.</p><ul><li><p><strong>Example</strong>: Reading <code>/proc/123/stat</code> gives statistics about process 123.</p></li></ul><div><hr></div><h4><strong>4. Communication Channels as Files</strong></h4><p>Inter-process communication (IPC) methods like pipes, sockets, and FIFOs are also treated as files. This allows processes to communicate by reading from and writing to these "files."</p><ul><li><p><strong>Example</strong>: A named pipe (<code>mkfifo pipe_name</code>) allows one process to write data while another reads it, just like a file.</p></li></ul><div><hr></div><h4><strong>5. Network Interfaces as Files</strong></h4><p>Network interfaces are treated as files in Linux, often found in <code>/proc</code> or <code>/sys</code>. This abstraction allows you to monitor or configure network behavior using file operations.</p><ul><li><p><strong>Example</strong>: Writing to <code>/proc/sys/net/ipv4/ip_forward</code> can enable or disable IP forwarding.</p></li></ul><div><hr></div><h4><strong>Benefits of </strong> "everything is a file"<strong> Philosophy</strong></h4><p>The "everything is a file" philosophy brings several advantages:</p><ol><li><p><strong>Simplicity</strong>: A uniform way to interact with diverse system components reduces complexity.</p></li><li><p><strong>Re-usability</strong>: Tools like <code>cat</code>, <code>echo</code>, and <code>grep</code> can interact with devices, processes, and data without needing specialized commands.</p></li><li><p><strong>Flexibility</strong>: Users can script and automate interactions with system components as easily as manipulating text files.</p></li></ol><h3><strong>Why Linux File Systems Matter</strong></h3><ol><li><p><strong>Uniformity</strong>: Linux treats everything as a file, from hardware devices to text files.</p></li><li><p><strong>Hierarchy</strong>: A single, unified directory structure begins at the root (<code>/</code>), eliminating the need for separate drive letters (e.g., <code>C:</code> in Windows).</p></li><li><p><strong>Flexibility</strong>: Supports various file systems, including Ext4, XFS, and NTFS.</p></li><li><p><strong>Security and Access Control</strong>: File permissions ensure only authorized users access specific files.</p></li></ol><div class="embedded-post-wrap" data-attrs="{&quot;id&quot;:152281368,&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/p/understanding-linux-file-systems-571&quot;,&quot;publication_id&quot;:3043184,&quot;publication_name&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd74e8425-0a13-40ad-86b5-27bdf5afe57f_800x800.png&quot;,&quot;title&quot;:&quot;Understanding Linux File Systems and Directory Structure - 2&quot;,&quot;truncated_body_text&quot;:&quot;How Linux File Systems Work&quot;,&quot;date&quot;:&quot;2024-11-28T12:09:28.257Z&quot;,&quot;like_count&quot;:0,&quot;comment_count&quot;:0,&quot;bylines&quot;:[{&quot;id&quot;:114001497,&quot;name&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;handle&quot;:&quot;gopakumarrajappan&quot;,&quot;previous_name&quot;:null,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e0e7bbb2-d0a8-45af-9002-89ad7c317651_800x800.jpeg&quot;,&quot;bio&quot;:&quot;Programming, Computer Networks, Distributed systems&quot;,&quot;profile_set_up_at&quot;:&quot;2024-09-19T19:51:04.852Z&quot;,&quot;publicationUsers&quot;:[{&quot;id&quot;:3096759,&quot;user_id&quot;:114001497,&quot;publication_id&quot;:3043184,&quot;role&quot;:&quot;admin&quot;,&quot;public&quot;:true,&quot;is_primary&quot;:false,&quot;publication&quot;:{&quot;id&quot;:3043184,&quot;name&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;subdomain&quot;:&quot;gopakumarrajappan&quot;,&quot;custom_domain&quot;:&quot;www.gopakumar-rajappan.com&quot;,&quot;custom_domain_optional&quot;:false,&quot;hero_text&quot;:&quot;First Principles: A Guiding Path to Understanding Tech Advancements&quot;,&quot;logo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d74e8425-0a13-40ad-86b5-27bdf5afe57f_800x800.png&quot;,&quot;author_id&quot;:114001497,&quot;theme_var_background_pop&quot;:&quot;#FF6719&quot;,&quot;created_at&quot;:&quot;2024-09-19T19:51:30.712Z&quot;,&quot;rss_website_url&quot;:null,&quot;email_from_name&quot;:null,&quot;copyright&quot;:&quot;GOPAKUMAR RAJAPPAN&quot;,&quot;founding_plan_name&quot;:null,&quot;community_enabled&quot;:true,&quot;invite_only&quot;:false,&quot;payments_state&quot;:&quot;enabled&quot;,&quot;language&quot;:null,&quot;explicit&quot;:false,&quot;is_personal_mode&quot;:false}}],&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;utm_campaign&quot;:null,&quot;belowTheFold&quot;:true,&quot;type&quot;:&quot;newsletter&quot;,&quot;language&quot;:&quot;en&quot;,&quot;source&quot;:null}" data-component-name="EmbeddedPostToDOM"><a class="embedded-post" native="true" href="https://www.gopakumar-rajappan.com/p/understanding-linux-file-systems-571?utm_source=substack&amp;utm_campaign=post_embed&amp;utm_medium=web"><div class="embedded-post-header"><img class="embedded-post-publication-logo" src="https://substackcdn.com/image/fetch/$s_!0BMm!,w_56,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd74e8425-0a13-40ad-86b5-27bdf5afe57f_800x800.png" loading="lazy"><span class="embedded-post-publication-name">GOPAKUMAR RAJAPPAN</span></div><div class="embedded-post-title-wrapper"><div class="embedded-post-title">Understanding Linux File Systems and Directory Structure - 2</div></div><div class="embedded-post-body">How Linux File Systems Work&#8230;</div><div class="embedded-post-cta-wrapper"><span class="embedded-post-cta">Read more</span></div><div class="embedded-post-meta">a year ago &#183; GOPAKUMAR RAJAPPAN</div></a></div><p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.gopakumar-rajappan.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">GOPAKUMAR RAJAPPAN is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item></channel></rss>