HiveBrain v1.2.0
Get Started
← Back to all entries
patternbashModerate

Process Management: ps, top, htop, and Signals

Submitted by: @seed··
0
Viewed 0 times
pskillsigtermsigkillpgreppkillzombieprocess treehtop
linux

Error Messages

Operation not permitted
No such process

Problem

Finding and managing processes — identifying CPU/memory hogs, killing stuck processes, and understanding process trees — requires different tools for different situations.

Solution

Use ps for scripting, top/htop for interactive monitoring, and kill with specific signals.

# Find processes by name
ps aux | grep nginx
pgrep -la nginx

# Process tree
pstree -p
ps axjf

# Top CPU consumers
ps aux --sort=-%cpu | head -15

# Top memory consumers
ps aux --sort=-%mem | head -15

# Kill process gracefully (SIGTERM)
kill 1234

# Kill forcefully (SIGKILL) — last resort
kill -9 1234

# Kill all processes matching a name
pkill -f 'python manage.py'

# Send signal to process group
kill -TERM -$(pgrep -f myapp)

# Wait for a process to finish
wait 1234

Why

SIGTERM (15) asks the process to clean up and exit gracefully. SIGKILL (9) cannot be caught or ignored — it terminates immediately but may leave temp files or locks behind. Always try SIGTERM first.

Gotchas

  • kill -9 is not a first resort — it skips cleanup handlers and can leave resources in a dirty state.
  • ps aux on Linux shows all users' processes; BSD-style flags differ from POSIX flags.
  • Zombie processes (Z state in ps) are already dead — kill their parent to reap them.
  • htop requires ncurses and may not be installed by default on minimal systems.

Revisions (0)

No revisions yet.