<?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" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ cmd - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ cmd - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Wed, 26 Aug 2026 20:17:34 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/cmd/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ What is a Process ID? How to Use PIDs for Process Management ]]>
                </title>
                <description>
                    <![CDATA[ Have you ever wondered how a computer knows which program’s output to display, especially when multiple programs are running simultaneously? This is possible because of the Process ID (PID). A PID is a unique identifier that helps the operating syste... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/what-is-a-process-id-process-management-tutorial/</link>
                <guid isPermaLink="false">679bb8262a7ebc3c99ecb6ea</guid>
                
                    <category>
                        <![CDATA[ System administration ]]>
                    </category>
                
                    <category>
                        <![CDATA[ cmd ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Syeda Maham Fahim ]]>
                </dc:creator>
                <pubDate>Thu, 30 Jan 2025 17:34:30 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1738252940529/8ee6969c-7a74-4b2f-bd33-f2d48332e8e0.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Have you ever wondered how a computer knows which program’s output to display, especially when multiple programs are running simultaneously? This is possible because of the Process ID (PID).</p>
<p>A PID is a unique identifier that helps the operating system track and manage running programs.</p>
<p>In this article, we’ll explore what a Process ID (PID) is, why it’s important, and how you can use it to manage processes, including terminating a program when necessary.</p>
<h2 id="heading-understanding-pids-how-does-a-computer-identify-running-programs">Understanding PIDs: How Does a Computer Identify Running Programs?</h2>
<p>Let’s consider two Python scripts:</p>
<ul>
<li><p><code>hello_maham.py</code> → <code>print("Hello Maham")</code></p>
</li>
<li><p><code>hello_amna.py</code> → <code>print("Hello Amna")</code></p>
</li>
</ul>
<p>How does the computer know that <code>hello_maham.py</code> should show the output "Hello Maham" and not "Hello Amna" from <code>hello_amna.py</code>?</p>
<p>If you think it just happens magically, then think again! This happens because of something called a <strong>Process ID (PID)</strong>.</p>
<p>In any operating system, processes are constantly running in the background to execute tasks. Whether it’s a program you launched manually or a system task running automatically, each of these processes is assigned a unique PID.</p>
<p>Let’s break this down further.</p>
<h2 id="heading-what-is-a-process-id-pid">What is a Process ID (PID)?</h2>
<p>Simply put,</p>
<blockquote>
<p><em>A</em> <strong><em>Process ID (PID)</em></strong> <em>is a unique identifier assigned to each process running in an operating system.</em></p>
</blockquote>
<p>Let’s understand what’s going on in the background.</p>
<p>Whenever a program runs, no matter the language, it needs memory and time to execute. So, when you run a program, the operating system creates a new process for it. To identify the program, the computer assigns it a unique identifier – the <strong>Process ID</strong> – and then it begins execution.</p>
<p>Let’s revisit our previous example:</p>
<ul>
<li><p>When you run <code>hello_maham.py</code>, the system assigns a unique PID to it.</p>
</li>
<li><p>Similarly, when you run <code>hello_amna.py</code>, it gets its own unique PID.</p>
</li>
</ul>
<p>This is why the outputs of both scripts don’t overlap!</p>
<p>Now, you got it? Each time a new process is created, the system ensures that every process gets a different PID. This PID is used by the system to manage and interact with processes. Its called <strong>Uniqueness Of PIDs</strong></p>
<h3 id="heading-how-does-the-computer-handle-this-id">How Does the Computer Handle This ID?</h3>
<p>Now you may wonder, does the computer have millions of PIDs? After all, we could be running many programs at once.</p>
<p>The answer is <strong>no</strong>. Once a process ends, the PID becomes available again for reuse. This means that PIDs are reusable, and there is no shortage of them.</p>
<h3 id="heading-but-why-and-when-do-i-need-pids">But Why and When Do I Need PIDs?</h3>
<p>Now that you know what a PID is, you might be wondering: <strong>Why do I need this?</strong></p>
<p>Well, PIDs are actually very useful for system administrators and developers. They help in:</p>
<p><strong>System admins and developers manage processes</strong>. Like, if something’s not working properly, you need to be able to find and stop the specific process causing the issue, right?</p>
<p>PIDs are also important for <strong>resource management<em>.</em></strong> The operating system uses them to allocate memory and CPU time to each process, so no one program hogs everything.</p>
<h2 id="heading-how-to-find-the-pid-of-a-running-program">How to Find the PID of a Running Program</h2>
<p>Up until now, we've covered the theoretical concepts. Now, you might be wondering: How do I actually find the PID of a program on my computer?</p>
<p>Well, here are some simple ways to find the <strong>PID</strong> of a running program using various commands in the terminal.</p>
<p>Note, that I’ve used Bash to execute the PID command and included a screenshot for it. But for other terminals like CMD and PowerShell, the respective commands are mentioned at the end.</p>
<p>Some of these methods include:</p>
<h3 id="heading-1-using-the-ps-command">1. Using the <code>ps</code> Command</h3>
<p>The <code>ps</code> command shows a snapshot of the current running processes and their PIDs.</p>
<pre><code class="lang-bash">ps aux | grep &lt;program_name&gt;
</code></pre>
<p>Here’s an example:</p>
<pre><code class="lang-bash">ps aux | grep python
</code></pre>
<p>This command will display all the Python processes running on the system, along with their PIDs.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1737914130884/686568b8-77d5-439d-a08b-61e18d4e5d56.png" alt="Python processes running plus their PIDs" class="image--center mx-auto" width="875" height="195" loading="lazy"></p>
<h3 id="heading-2-using-the-top-command">2. Using the <code>top</code> Command</h3>
<p>The <code>top</code> command shows real-time information about processes running on the system, including their PIDs.</p>
<pre><code class="lang-bash">top
</code></pre>
<p>Look under the <strong>PID</strong> column to find the process you're interested in.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1737914189672/43f93890-2e06-42a8-b61b-9103227cf912.png" alt="Result of running the top command" class="image--center mx-auto" width="1066" height="782" loading="lazy"></p>
<h2 id="heading-how-to-kill-a-process-using-its-pid">How to Kill a Process Using its PID</h2>
<p>What if you want to <strong>kill</strong> the program? Whether it’s a cron job or a program that is misbehaving or running for too long, how can you stop it using the PID?</p>
<p>Let’s go through how you can do that:</p>
<h3 id="heading-1-using-the-kill-command">1. Using the <code>kill</code> Command</h3>
<p>To terminate a process, use the <code>kill</code> command followed by the PID:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">kill</span> &lt;PID&gt;
</code></pre>
<p>Here’s an example:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">kill</span> 1234
</code></pre>
<p>This command will gracefully terminate the process with PID <code>1234</code>.</p>
<h3 id="heading-2-using-the-kill-9-command-force-kill">2. Using the <code>kill -9</code> Command (Force Kill)</h3>
<p>If the process does not stop after using the regular <code>kill</code> command, you can force kill it using the <code>kill -9</code> command:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">kill</span> -9 &lt;PID&gt;
</code></pre>
<p>Here’s an example:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">kill</span> -9 1234
</code></pre>
<p>This forcefully terminates the process and bypasses any shutdown procedures it may have, so make sure you use it with caution.</p>
<h2 id="heading-how-to-stop-cron-jobs-using-a-pid-practical-example">How to Stop Cron Jobs Using a PID – Practical Example</h2>
<p>So, let’s say you’ve got a cron job running, and it’s acting up. How do you stop it?</p>
<p>Cron jobs are scheduled tasks that run automatically at specific intervals.</p>
<p>If you need to stop a running cron job, you can use the PID of the process running the cron job.</p>
<h3 id="heading-stop-a-running-cron-job">Stop a Running Cron Job</h3>
<p>If you need to stop a running cron job, you can use the PID of the process running the cron job.</p>
<p>Here’s how to kill a cron job:</p>
<ol>
<li><p><strong>Find the PID</strong>: Use the <code>ps</code> or <code>pgrep</code> command to find the PID of the cron job. Example:</p>
<pre><code class="lang-bash"> ps aux | grep cron
</code></pre>
</li>
<li><p><strong>Kill the Cron Job</strong>: Once you find the PID of the cron job, use the <code>kill</code> or <code>kill -9</code> command to stop it.</p>
</li>
</ol>
<h2 id="heading-commands-for-other-terminals">Commands For Other Terminals:</h2>
<p>Here’s how to manage processes in different terminals:</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Action</td><td>CMD Command</td><td>PowerShell Command</td><td>Bash Command</td></tr>
</thead>
<tbody>
<tr>
<td><strong>List all processes</strong></td><td><code>tasklist</code></td><td><code>Get-Process</code></td><td><code>ps aux</code></td></tr>
<tr>
<td><strong>Find process by name</strong></td><td><code>tasklist</code></td><td><code>findstr &lt;name&gt;</code></td><td><code>Get-Process</code></td></tr>
<tr>
<td><strong>Kill process by PID</strong></td><td><code>taskkill /PID &lt;PID&gt;</code></td><td><code>Stop-Process -Id &lt;PID&gt;</code></td><td><code>kill &lt;PID&gt;</code></td></tr>
<tr>
<td><strong>Force kill process</strong></td><td><code>taskkill /F /PID &lt;PID&gt;</code></td><td><code>Stop-Process -Id &lt;PID&gt; -Force</code></td><td><code>kill -9 &lt;PID&gt;</code></td></tr>
</tbody>
</table>
</div><h2 id="heading-conclusion">Conclusion</h2>
<p>Understanding <strong>Process IDs</strong> is key to managing processes on your computer. With simple commands, you can easily find and stop problematic processes, ensuring smooth system operation.</p>
<p>So, stay in control of your system with PIDs!</p>
<p><strong>Stay connected — @syedamahamfahim 🐬</strong></p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
