Skip to main content

Linux Process Management

Learn to monitor, control, and manage processes in Linux. A process is simply a running program — every command you type, every service running on your server, every background task is a process. Understanding processes is like understanding traffic flow in a city: you need to know what is running, what is stuck, and how to clear a jam.

Viewing Processes

When to use what: Use htop for interactive exploration (what is eating my CPU right now?). Use ps aux for scripting and one-off checks. Use pstree when you need to understand process relationships, like which worker was spawned by which master process.

Signals and Process Control

Killing a process is not always about force — Linux uses signals to communicate with processes. Think of signals as tapping someone on the shoulder (polite) versus pulling the fire alarm (forceful).

Common Signals Reference

Always try SIGTERM before SIGKILL. SIGKILL (kill -9) does not let the process clean up — it can leave behind lock files, corrupt data being written to disk, or leave child processes orphaned. Give SIGTERM a few seconds to work first.

Background and Foreground Jobs

When you are working in a terminal, you often need to run something in the background while continuing other work. This is job control.
Production tip: For long-running tasks on remote servers, use tmux or screen instead of nohup. They give you a persistent terminal session you can detach from and reattach to later, even after disconnecting SSH.

Systemd Services

Modern Linux distributions use systemd to manage services (daemons). Systemd is the first process that starts (PID 1) and it manages the lifecycle of everything else. Think of it as the conductor of an orchestra — it starts services in the right order, restarts them if they crash, and tracks their logs.

Creating a Custom Service

When you deploy your own application, you write a unit file to let systemd manage it. This is one of the most practical skills in this chapter — every production application should be managed by systemd rather than run manually in a screen or tmux session.
Common systemd pitfalls: (1) Forgetting daemon-reload after editing a unit file — systemd uses a cached copy and your changes are ignored. (2) Using Type=simple when the app forks — systemd tracks the wrong PID and thinks the service died. (3) Not setting Restart=on-failure — a single crash at 3 AM takes your service offline until a human notices. (4) Running services as root when they do not need root privileges — use User= and Group= to run as a dedicated service account.

Key Takeaways

  • Every running program is a process with a PID, owner, and resource usage
  • Use htop for interactive monitoring, ps aux for scripting
  • Send SIGTERM first, SIGKILL only as a last resort
  • Job control (&, fg, bg, Ctrl+Z) manages processes within your terminal session
  • Systemd manages long-running services: start, stop, restart, and auto-start on boot
  • Always check systemctl status and journalctl -u when debugging service failures
  • Write custom unit files to let systemd manage your own applications

Next: Linux Networking →