Quick take: Use ps aux to list running processes and find a PID, then kill PID to stop one gracefully or kill -9 PID to force it. Use pkill name or killall name to stop processes by name.
Introduction
Managing processes is core to Linux administration, and two commands handle most of it: ps lists what is running, and kill sends signals to stop it. Around them sit helpers like pgrep, pkill, and killall for working with processes by name.
This guide covers listing and finding processes, the signals kill can send, and the safe way to terminate a misbehaving process.
Syntax
The basic syntax of the ps and kill command is:
ps [OPTIONS]
kill [-SIGNAL] PIDCommon Options and Parameters
The most useful options and parameters for the ps and kill command:
| Option | Description |
|---|---|
| ps aux | List all processes with user, CPU, and memory (BSD style). |
| ps -ef | List all processes in full format (System V style). |
| kill PID | Send the default TERM signal to stop a process gracefully. |
| kill -9 PID | Send KILL — force the process to stop immediately. |
| kill -15 PID | Send TERM explicitly (the polite default). |
| kill -1 PID | Send HUP — often reloads a service's configuration. |
| pgrep name | Print the PIDs of processes matching a name. |
| pkill name | Signal processes by name. |
| killall name | Signal all processes with an exact name. |
Practical Examples
Real ps and kill commands you can run today:
# List all processes
ps aux
# Find a specific process and its PID
ps aux | grep nginx
# Stop a process gracefully by PID
kill 4821
# Force-kill an unresponsive process
kill -9 4821
# Stop every matching process by name
pkill firefox
# Find PIDs by name
pgrep -l sshd
# Reload a service by sending HUP
sudo kill -1 $(pgrep nginx | head -1)Understanding Linux Signals
kill does not only “kill” — it sends a signal, and choosing the right one matters. The common ones are:
| Signal | Number | Effect |
|---|---|---|
| SIGTERM | 15 | Polite request to stop; the process can clean up (the default). |
| SIGKILL | 9 | Forced, immediate termination; cannot be caught or ignored. |
| SIGHUP | 1 | Hang-up; many daemons reload their config on this signal. |
| SIGINT | 2 | Interrupt, the same as pressing Ctrl+C. |
Always try SIGTERM first so the process can flush data and close files cleanly. Reserve SIGKILL for processes that ignore TERM — pulling the plug with -9 can leave temporary files or locks behind.
Finding and Stopping Runaway Processes
When a server is overloaded, the goal is to find the offending process quickly and stop it without harming others. Combine ps with sorting, or jump straight to the live monitors.
# Top 5 CPU consumers
ps aux --sort=-%cpu | head -6
# Top 5 memory consumers
ps aux --sort=-%mem | head -6
# Stop every worker of a runaway app by name
pkill -f 'python worker.py'The -f flag to pkill matches against the full command line, which is essential when many processes share the same executable name but differ in their arguments.
Tips and Best Practices
- Always try a plain
kill(TERM) first — it lets the process clean up. Reservekill -9(KILL) for processes that ignore it. - Use
pgrep/pkillinstead of parsingps | grepby hand — they are safer and avoid matching the grep process itself. ps aux --sort=-%mem | headquickly shows the biggest memory consumers.
Final Thoughts
ps and kill are the foundation of process control in Linux: list with ps aux, find the PID, then signal it with kill. Prefer a graceful TERM before a forceful -9, and use pgrep and pkill to work by name. For a live, interactive view of processes, move on to top and htop.
FAQ: ps and kill Command in Linux
How do I list running processes in Linux?+
Use ps aux for a full list with CPU and memory, or ps -ef for the System V format. To find one process, pipe into grep: ps aux | grep nginx.
How do I kill a process by PID?+
Run kill PID to stop it gracefully. If it ignores that, use kill -9 PID to force termination. Find the PID first with ps or pgrep.
What is the difference between kill and kill -9?+
Plain kill sends SIGTERM (15), asking the process to shut down cleanly. kill -9 sends SIGKILL, which the kernel enforces immediately without giving the process a chance to clean up. Use -9 only as a last resort.
How do I kill a process by name?+
Use pkill name or killall name to signal all matching processes, for example pkill chrome. pgrep name lists their PIDs first if you want to check.
How do I find which process uses the most CPU or memory?+
Sort ps output: ps aux --sort=-%cpu | head for CPU or --sort=-%mem for memory. For a live view, use top or htop.
Need help with Linux servers or infrastructure?
Work directly with Muhammad Irfan Aslam for Linux, Ubuntu, Docker, DevOps, cloud, CI/CD, or infrastructure support.
Hire Me for Support