Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      June 1, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      June 1, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      June 1, 2025

      How To Prevent WordPress SQL Injection Attacks

      June 1, 2025

      7 MagSafe accessories that I recommend every iPhone user should have

      June 1, 2025

      I replaced my Kindle with an iPad Mini as my ebook reader – 8 reasons why I don’t regret it

      June 1, 2025

      Windows 11 version 25H2: Everything you need to know about Microsoft’s next OS release

      May 31, 2025

      Elden Ring Nightreign already has a duos Seamless Co-op mod from the creator of the beloved original, and it’ll be “expanded on in the future”

      May 31, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      Student Record Android App using SQLite

      June 1, 2025
      Recent

      Student Record Android App using SQLite

      June 1, 2025

      When Array uses less memory than Uint8Array (in V8)

      June 1, 2025

      Laravel 12 Starter Kits: Definite Guide Which to Choose

      June 1, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Photobooth is photobooth software for the Raspberry Pi and PC

      June 1, 2025
      Recent

      Photobooth is photobooth software for the Raspberry Pi and PC

      June 1, 2025

      Le notizie minori del mondo GNU/Linux e dintorni della settimana nr 22/2025

      June 1, 2025

      Rilasciata PorteuX 2.1: Novità e Approfondimenti sulla Distribuzione GNU/Linux Portatile Basata su Slackware

      June 1, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»What is a Process ID? How to Use PIDs for Process Management

    What is a Process ID? How to Use PIDs for Process Management

    January 30, 2025

    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 system track and manage running programs.

    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.

    Understanding PIDs: How Does a Computer Identify Running Programs?

    Let’s consider two Python scripts:

    • hello_maham.py → print("Hello Maham")

    • hello_amna.py → print("Hello Amna")

    How does the computer know that hello_maham.py should show the output “Hello Maham” and not “Hello Amna” from hello_amna.py?

    If you think it just happens magically, then think again! This happens because of something called a Process ID (PID).

    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.

    Let’s break this down further.

    What is a Process ID (PID)?

    Simply put,

    A Process ID (PID) is a unique identifier assigned to each process running in an operating system.

    Let’s understand what’s going on in the background.

    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 Process ID – and then it begins execution.

    Let’s revisit our previous example:

    • When you run hello_maham.py, the system assigns a unique PID to it.

    • Similarly, when you run hello_amna.py, it gets its own unique PID.

    This is why the outputs of both scripts don’t overlap!

    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 Uniqueness Of PIDs

    How Does the Computer Handle This ID?

    Now you may wonder, does the computer have millions of PIDs? After all, we could be running many programs at once.

    The answer is no. Once a process ends, the PID becomes available again for reuse. This means that PIDs are reusable, and there is no shortage of them.

    But Why and When Do I Need PIDs?

    Now that you know what a PID is, you might be wondering: Why do I need this?

    Well, PIDs are actually very useful for system administrators and developers. They help in:

    System admins and developers manage processes. Like, if something’s not working properly, you need to be able to find and stop the specific process causing the issue, right?

    PIDs are also important for resource management. The operating system uses them to allocate memory and CPU time to each process, so no one program hogs everything.

    How to Find the PID of a Running Program

    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?

    Well, here are some simple ways to find the PID of a running program using various commands in the terminal.

    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.

    Some of these methods include:

    1. Using the ps Command

    The ps command shows a snapshot of the current running processes and their PIDs.

    ps aux | grep <program_name>
    

    Here’s an example:

    ps aux | grep python
    

    This command will display all the Python processes running on the system, along with their PIDs.

    Python processes running plus their PIDs

    2. Using the top Command

    The top command shows real-time information about processes running on the system, including their PIDs.

    top
    

    Look under the PID column to find the process you’re interested in.

    Result of running the top command

    How to Kill a Process Using its PID

    What if you want to kill 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?

    Let’s go through how you can do that:

    1. Using the kill Command

    To terminate a process, use the kill command followed by the PID:

    kill <PID>
    

    Here’s an example:

    kill 1234
    

    This command will gracefully terminate the process with PID 1234.

    2. Using the kill -9 Command (Force Kill)

    If the process does not stop after using the regular kill command, you can force kill it using the kill -9 command:

    kill -9 <PID>
    

    Here’s an example:

    kill -9 1234
    

    This forcefully terminates the process and bypasses any shutdown procedures it may have, so make sure you use it with caution.

    How to Stop Cron Jobs Using a PID – Practical Example

    So, let’s say you’ve got a cron job running, and it’s acting up. How do you stop it?

    Cron jobs are scheduled tasks that run automatically at specific intervals.

    If you need to stop a running cron job, you can use the PID of the process running the cron job.

    Stop a Running Cron Job

    If you need to stop a running cron job, you can use the PID of the process running the cron job.

    Here’s how to kill a cron job:

    1. Find the PID: Use the ps or pgrep command to find the PID of the cron job. Example:

       ps aux | grep cron
      
    2. Kill the Cron Job: Once you find the PID of the cron job, use the kill or kill -9 command to stop it.

    Commands For Other Terminals:

    Here’s how to manage processes in different terminals:

    Action CMD Command PowerShell Command Bash Command
    List all processes tasklist Get-Process ps aux
    Find process by name tasklist findstr <name> Get-Process
    Kill process by PID taskkill /PID <PID> Stop-Process -Id <PID> kill <PID>
    Force kill process taskkill /F /PID <PID> Stop-Process -Id <PID> -Force kill -9 <PID>

    Conclusion

    Understanding Process IDs is key to managing processes on your computer. With simple commands, you can easily find and stop problematic processes, ensuring smooth system operation.

    So, stay in control of your system with PIDs!

    Stay connected — @syedamahamfahim 🐬

    Source: freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleLangchain Alternatives You Can Use to Build AI and Agentic Workflows
    Next Article Learn the Basics of API Security

    Related Posts

    Artificial Intelligence

    Markus Buehler receives 2025 Washington Award

    June 1, 2025
    Artificial Intelligence

    LWiAI Podcast #201 – GPT 4.5, Sonnet 3.7, Grok 3, Phi 4

    June 1, 2025
    Leave A Reply Cancel Reply

    Hostinger

    Continue Reading

    Get 4 free iPhone 16 Pro phones from T-Mobile with this holiday deal

    Development

    Taking RWD To The Extreme

    Tech & Work

    The Secret of the World’s Darkest Prison

    Artificial Intelligence

    Open-Source Meets Design Tooling With Penpot

    Development

    Highlights

    Comcast’s new low-latency internet is literally game-changing, and these cities will get it first

    January 29, 2025

    The company’s new tech could make slow internet a thing of the past. Source: Latest…

    14 Best Free and Open Source CLI Tools to Find and Delete Duplicate Files

    December 17, 2024

    Alternatives to popular CLI tools: Wget

    January 10, 2025

    BayMark Health Services Reports Data Breach, Exposing Patient Information

    January 10, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.