The ps and kill Commands — Managing Processes
Overview
Managing processes is a core part of Linux server administration. The ps command shows what’s currently running, and the kill command lets you stop processes that are stuck, consuming too many resources, or no longer needed.
The ps Command
Basic Usage
ps
This shows only processes in your current terminal session — usually not very informative.
View All Processes (Most Common)
ps aux
This displays every running process on the system with detailed information:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.1 169316 11752 ? Ss Jan01 0:05 /sbin/init
mysql 1234 2.5 12.0 1286452 245680 ? Sl Jan01 45:12 /usr/sbin/mysqld
www-data 5678 0.3 1.2 456780 24560 ? S 08:15 0:02 /usr/sbin/apache2
Understanding the Columns
| Column | Description |
|---|---|
| USER | The user who owns the process |
| PID | Process ID — the unique identifier you need for kill |
| %CPU | CPU usage percentage |
| %MEM | Memory usage percentage |
| VSZ | Virtual memory size (KB) |
| RSS | Resident set size — actual physical memory used (KB) |
| TTY | Terminal associated with the process (? means no terminal) |
| STAT | Process state (see below) |
| START | When the process started |
| TIME | Total CPU time consumed |
| COMMAND | The command that launched the process |
Common Process States (STAT)
| State | Meaning |
|---|---|
R | Running or runnable |
S | Sleeping (waiting for an event) |
D | Uninterruptible sleep (usually I/O) |
Z | Zombie — process finished but not cleaned up by parent |
T | Stopped |
Finding a Specific Process
Combine ps with grep:
ps aux | grep apache
ps aux | grep mysql
ps aux | grep php
Show only your processes
ps -u username
The kill Command
Basic Usage
kill PID
This sends a SIGTERM (signal 15) — a polite request for the process to shut down gracefully.
Force Kill
If a process ignores SIGTERM:
kill -9 PID
SIGKILL (signal 9) immediately terminates the process. Use this as a last resort — it gives the process no chance to clean up.
Kill by Name
killall process_name
Example:
killall php-cgi
This kills all processes matching that name.
Alternative: pkill
pkill -f "python3 script.py"
The -f flag matches against the full command line, not just the process name.
Common Kill Signals
| Signal | Number | Purpose |
|---|---|---|
SIGHUP | 1 | Reload configuration |
SIGTERM | 15 | Graceful termination (default) |
SIGKILL | 9 | Forced termination |
SIGSTOP | 19 | Pause the process |
SIGCONT | 18 | Resume a paused process |
Reload a service without stopping it
kill -HUP PID
Useful for making services like Apache or Nginx reload their configuration.
Practical Hosting Examples
Find and kill a stuck PHP process
ps aux | grep php
# Note the PID from the output
kill 12345
Kill all user processes (emergency reset)
killall -u username
Check if MySQL is running
ps aux | grep mysql
Find zombie processes
ps aux | grep 'Z'
Tips
- Always try
kill PID(SIGTERM) before resorting tokill -9 PID. - Use
ps aux --sort=-%cpu | head -20to see the top 20 CPU-consuming processes. - Use
ps aux --sort=-%mem | head -20to see the top 20 memory-consuming processes. - On shared hosting, you typically can only kill your own processes. Contact your hosting provider for system-level issues.