Back to Blog
Lesson 20 of the Linux: Linux Command Line for Developers course
LinuxAugust 7, 20264 min read

Introduction to Processes: A Linux Guide for Developers

Master Linux processes by learning to use the ps command, identifying PIDs, and understanding parent/child relationships to manage your server effectively.

linuxprocessescommand-linedevopssystem-administration
A person reads 'Python for Unix and Linux System Administration' indoors.

Previously in this course, we covered Understanding Users and Groups in Linux: A Developer's Guide, where we learned how the system identifies who is executing commands. In this lesson, we shift our focus from the who to the what: how the Linux kernel executes and tracks the programs running on your server.

Understanding Processes from First Principles

In Linux, a "process" is simply an instance of a running program. When you execute a command, the kernel allocates memory, CPU time, and resources to that specific execution. Every process is tracked by the kernel using a unique identifier called a Process ID (PID).

Processes exist in a hierarchy. Every process is spawned by another process, known as the Parent Process. The very first process started by the Linux kernel when the system boots is init (or systemd), which carries the PID 1. Every other process on your system is a descendant of this initial process.

Understanding this tree structure is vital when you start managing services, as killing a parent process often terminates all of its children—a common scenario when debugging our web server.

Inspecting System Activity with ps

The primary tool for viewing these processes is ps (Process Status). While you can run ps by itself, it is most useful with flags that provide a comprehensive view of the system.

A standard, highly informative command is ps aux:

  • a: Shows processes for all users.
  • u: Displays the process's user/owner.
  • x: Includes processes that aren't attached to a terminal (like background services).

Worked Example: Analyzing Running Processes

Let’s look at how to interpret this output. Open your terminal and run:

Bash
ps aux | head -n 5

You will see columns similar to these:

USERPID%CPU%MEMCOMMAND
root10.00.1/sbin/init
root4520.00.2/lib/systemd/systemd-journald
user12040.10.5-bash
  • USER: The user account running the process.
  • PID: The unique ID used to identify and manage the process.
  • COMMAND: The actual executable running.

If you want to see the parent/child relationship specifically, you can use ps -ef. The PPID column represents the "Parent Process ID." You can trace how your shell (bash) was started by a terminal emulator or an SSH session by looking at its PPID.

Hands-on Exercise: Tracking Your Web Server

In our ongoing project, we need to ensure our server environment is clean. Let's practice identifying the processes currently running in your user session.

  1. Open two terminal windows.
  2. In the first window, run sleep 100. This creates a simple process that does nothing but wait.
  3. In the second window, find the PID of your sleep command:
    Bash
    ps aux | grep sleep
  4. Note the PID. Now, look at your shell process:
    Bash
    ps -f
    Compare the PPID of the sleep command to the PID of your shell. You will see they are linked!

Common Pitfalls

  • Confusing UID and PID: Remember that User IDs (UIDs) identify users, while PIDs identify instances of programs.
  • Ignoring Background Processes: Many processes run in the background without a terminal attached. Using ps aux ensures you don't miss these; using just ps will often only show the processes tied to your current session.
  • Zombies: Sometimes you will see a process labeled <defunct>. This is a "zombie" process—it has finished execution but is waiting for its parent to acknowledge it. They don't consume CPU, but they do hold onto a PID entry in the kernel table.

FAQ

What happens if I kill PID 1? On most modern Linux systems, systemd (PID 1) is protected. The kernel will refuse to kill it, as doing so would cause an immediate system panic (crash).

Why do I see the same command listed multiple times? Many modern applications, including web servers like Nginx or Apache, spawn multiple "worker processes" to handle concurrent requests. Each worker gets its own PID, even if they all belong to the same program.

Is ps real-time? No. ps provides a snapshot of the system at the exact moment you ran the command. For a live, updating view, we will explore top in the next lesson.

Recap

We have established that Linux manages programs as processes, each assigned a unique PID. We explored how to use ps aux to list these processes and identified the hierarchical nature of parent and child processes. Mastering these basics is the foundation for managing the services and web server configurations we will build throughout the rest of this course.

Up next: Real-time Monitoring with Top

Similar Posts