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

      Sunshine And March Vibes (2025 Wallpapers Edition)

      June 2, 2025

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

      June 2, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      June 2, 2025

      How To Prevent WordPress SQL Injection Attacks

      June 2, 2025

      How Red Hat just quietly, radically transformed enterprise server Linux

      June 2, 2025

      OpenAI wants ChatGPT to be your ‘super assistant’ – what that means

      June 2, 2025

      The best Linux VPNs of 2025: Expert tested and reviewed

      June 2, 2025

      One of my favorite gaming PCs is 60% off right now

      June 2, 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

      `document.currentScript` is more useful than I thought.

      June 2, 2025
      Recent

      `document.currentScript` is more useful than I thought.

      June 2, 2025

      Adobe Sensei and GenAI in Practice for Enterprise CMS

      June 2, 2025

      Over The Air Updates for React Native Apps

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

      You can now open ChatGPT on Windows 11 with Win+C (if you change the Settings)

      June 2, 2025
      Recent

      You can now open ChatGPT on Windows 11 with Win+C (if you change the Settings)

      June 2, 2025

      Microsoft says Copilot can use location to change Outlook’s UI on Android

      June 2, 2025

      TempoMail — Command Line Temporary Email in Linux

      June 2, 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

    Security

    New Chrome Zero-Day Actively Exploited; Google Issues Emergency Out-of-Band Patch

    June 3, 2025
    Security

    How One Path Traversal in Grafana Unleashed XSS, Open Redirect and SSRF (CVE-2025–4123)

    June 3, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    CVE-2025-3802 – Tenda W12 and i24 HTTPd cgiPingSet Stack-Based Buffer Overflow

    Common Vulnerabilities and Exposures (CVEs)

    Streamlining data collection for improved salmon population management

    Artificial Intelligence

    A Resize Plugin for Alpine.js

    Development

    What Are Network Latency And Round Trip Time (RTT)?

    Web Development

    Highlights

    Development

    NativePHP Windows Builds are Here

    May 2, 2024

    Windows support for NativePHP was announced, which means that you can now build applications for the Windows…

    Brisa v0.2.10 release

    April 5, 2025

    Skribisto – writing tool for Linux

    December 19, 2024

    ARX Robotics and Daimler Truck join forces for next-gen military vehicles

    March 28, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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