Skip to content

Process Management

Monitor, control, and manage running processes using ps, top, kill, and service managers.

What you'll learn

  • What processes are and how the OS manages them
  • Listing and inspecting processes with ps and top
  • Sending signals to processes with kill
  • Running long-lived services with systemd and pm2

Concept

What Is a Process?

A process is a running instance of a program. When you launch an application, the operating system creates a process, assigns it a unique PID (process ID), and gives it memory and resources. Processes can start child processes, forming a process tree. Understanding processes is essential for DevOps because servers run many processes simultaneously, and you need to monitor, restart, and sometimes kill them.

Listing and Inspecting Processes

The ps command lists processes. ps aux shows all processes on the system with details. top and htop provide a real-time, continuously updating view of CPU and memory usage per process. These tools help you find resource hogs, identify runaway processes, and understand what is running on a server at any given moment.

Signals and kill

Every process can receive signals — simple messages that tell it to do something. kill PID sends SIGTERM (terminate), which lets the process clean up before exiting. kill -9 PID sends SIGKILL, which forces immediate termination without cleanup. kill -l lists all available signals. Always try SIGTERM first; use SIGKILL only as a last resort because it can leave files corrupted or resources leaked.

Service Managers

For long-lived services like web servers and databases, you use a service manager. On Linux, systemd is the standard — systemctl start nginx, systemctl enable nginx, systemctl status nginx. For Node.js applications, pm2 is popular — it restarts crashed processes, manages logs, and handles clustering. Service managers ensure your applications start on boot and recover from failures automatically.

Process Lifecycle

Processes go through a lifecycle: created, running, sleeping, stopped, or zombie. A zombie process has finished but its parent hasn't acknowledged its exit — it still occupies a PID. Orphaned zombie processes can accumulate and exhaust the PID table. Use ps aux to spot them (they appear with status Z). Understanding this lifecycle helps you diagnose stuck services, memory leaks, and resource exhaustion — all common production issues that DevOps engineers investigate regularly.

Example

              # List and inspect processes
ps aux | grep node              # find all node processes
top -b -n 1 | head -20          # snapshot of top processes

# Start a process in the background
node server.js &
echo "Started with PID $!"

# Send signals to a process
kill -SIGTERM 12345             # gracefully stop process 12345
kill -SIGKILL 12345             # force kill if it won't stop

# Manage services with systemd
sudo systemctl start nginx
sudo systemctl enable nginx     # start on boot
sudo systemctl status nginx
            

ps and top show running processes. kill sends signals to stop them. systemctl manages long-lived services through systemd, the standard Linux init system.

Try it

Common mistakes

The mistake

Using kill -9 (SIGKILL) as the first option

The fix

Always try kill (SIGTERM) first. SIGKILL prevents the process from cleaning up, which can corrupt files, leave ports bound, or leak database connections.

The mistake

Forgetting to enable services for boot

The fix

Use systemctl enable <service> so the service starts automatically after a reboot. Without enable, your server will be down after every restart.

Practice Process Management

1 exercise

Practice Process Management

Look up unfamiliar terms

A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.

View glossary

Build real projects

Apply what you learned by building guided projects with starter code and solutions.

View projects

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors