System Administration Featured

Linux Process Management Commands Cheatsheet

Comprehensive reference for Linux process management including ps, top, htop, kill commands, Linux signals, process states, background job control, terminal multiplexers, and system monitoring tools for effective process administration.

#linux #process-management #signals #kill #ps #top #sysadmin #monitoring
Sign In to Download

Free account required

What is Process Management?

Process management in Linux allows you to monitor, control, and manipulate running programs. Each process has a unique Process ID (PID) and can be controlled using various commands and signals. Understanding process management is essential for system administration, troubleshooting, and resource optimization.

Whether you're managing a small application or running production workloads on enterprise VPS infrastructure, mastering process control is essential. Monitor your processes effectively using our performance dashboard and compare server performance across different configurations.

Process ID (PID)
Unique identifier for each running process
Signals
Messages sent to processes to control behavior
Job Control
Manage foreground and background processes

Viewing Processes

ps - Display process information

$ ps                    # Show processes in current shell
$ ps aux                # Show all processes with detailed info
$ ps aux | grep nginx   # Find specific process
$ ps -ef                # Full format listing
$ ps -u username        # Show user's processes

Common columns: PID (Process ID), USER, %CPU, %MEM, VSZ (Virtual Memory), RSS (Physical Memory), TTY, STAT (State), START, TIME, COMMAND

pstree - Display processes in tree structure

$ pstree                # Show process tree
$ pstree -p             # Show with PIDs
$ pstree username       # Show user's process tree

top - Real-time process monitor

$ top                   # Interactive process viewer
$ top -u username       # Show user's processes
$ top -p PID            # Monitor specific process

Interactive commands in top:

  • k - Kill process
  • r - Renice (change priority)
  • M - Sort by memory usage
  • P - Sort by CPU usage
  • q - Quit

htop - Interactive process viewer (enhanced)

$ htop                  # Better alternative to top
$ htop -u username      # Show user's processes

Provides color-coded display, mouse support, and easier navigation than top

btop++ / bottom - Modern process viewers

$ btop                  # Modern, beautiful process viewer
$ btop++                # C++ version with advanced features
$ bottom                # Rust-based alternative (btm)

Modern alternatives with beautiful TUI, graphs, and advanced monitoring capabilities. For more essential commands, see our Linux Commands cheatsheet.

lsof - List open files and processes

$ lsof                  # List all open files
$ lsof -u username      # Show user's open files
$ lsof -i :80           # Show processes using port 80
$ lsof -p PID           # Show files opened by process

Essential for troubleshooting network connections and file access. Learn more about network monitoring techniques.

Controlling Processes

kill - Send signal to terminate or interrupt a process

$ kill PID              # Send default signal (SIGTERM)
$ kill -9 PID           # Force kill (SIGKILL)
$ kill -15 PID          # Graceful termination (SIGTERM)
$ kill -l               # List all available signals
$ kill -SIGHUP PID      # Send hangup signal

Default signal is SIGTERM (15) which allows graceful shutdown. SIGKILL (9) forces immediate termination.

killall - Kill all processes that match a specific process name

$ killall nginx         # Kill all nginx processes
$ killall -9 nginx      # Force kill all nginx processes
$ killall -u username   # Kill all processes by user

pkill - Send signal to processes based on name or other attributes

$ pkill nginx           # Kill processes by name
$ pkill -9 nginx        # Force kill by name
$ pkill -u username     # Kill user's processes
$ pkill -t pts/0        # Kill processes on terminal

pgrep - Find process IDs of running programs based on given criteria

$ pgrep nginx           # Find PIDs by name
$ pgrep -u username     # Find user's process PIDs
$ pgrep -l nginx        # Show PIDs with names
$ pgrep -a nginx        # Show full command line

trap - Allows shell scripts to watch for and intercept signals

#!/bin/bash
# Trap signals in shell script
trap "echo 'Signal received!'; exit" SIGINT SIGTERM

# Your script here
while true; do
    echo "Running..."
    sleep 1
done

Useful for cleanup operations when script is interrupted

Important: Signal Safety

  • SIGTERM (15): Always try this first - allows graceful shutdown
  • SIGKILL (9): Use as last resort - forces immediate termination, no cleanup
  • SIGHUP (1): Often used to reload configuration without restart

Linux Signals Reference

Signals are software interrupts that provide a way to handle asynchronous events. Each signal has a unique number and name.

Signal Value Description
SIGHUP 1 Hangup - Terminates process, often used to reload config
SIGINT 2 Interrupt - Sent by Ctrl+C, interrupts the process
SIGQUIT 3 Quit - Sent by Ctrl+\, stops the process with core dump
SIGKILL 9 Kill - Unconditionally terminates, cannot be caught or ignored
SIGTERM 15 Terminate - Graceful termination, allows cleanup (default)
SIGSTOP 17 Stop - Unconditionally stops process (cannot be caught)
SIGTSTP 18 Terminal stop - Sent by Ctrl+Z, pauses process
SIGCONT 19 Continue - Resumes a stopped process

List All Available Signals

$ kill -l               # List all signals with numbers
$ trap -l               # Alternative way to list signals

Background Job Control

& - Execute command in background

$ command &             # Run command in background
$ long_script.sh &      # Run script in background
$ sleep 100 &           # Example background job

Allows you to continue using the terminal while command runs

jobs - List active jobs in current shell session

$ jobs                  # List all jobs
$ jobs -l               # Show with PID
$ jobs -r               # Show running jobs only
$ jobs -s               # Show stopped jobs only

Jobs are numbered [1], [2], etc. Use job number with % (e.g., %1)

bg - Send job to background

$ bg                    # Resume most recent stopped job in background
$ bg %1                 # Resume job 1 in background
$ bg %2                 # Resume job 2 in background

fg - Bring job to foreground

$ fg                    # Bring most recent job to foreground
$ fg %1                 # Bring job 1 to foreground
$ fg %2                 # Bring job 2 to foreground

nohup - Run process that will continue even if terminal is closed

$ nohup command &       # Run immune to hangups
$ nohup ./script.sh &   # Output saved to nohup.out
$ nohup command > output.log 2>&1 &  # Redirect output

Process continues running even after you log out or close the terminal. For automated task scheduling, check our Cron cheatsheet and learn about secure SSH session management.

Typical Workflow

# Start a job
$ sleep 300 &
[1] 12345

# Check jobs
$ jobs
[1]+  Running    sleep 300 &

# Bring to foreground
$ fg %1

# Press Ctrl+Z to pause
^Z
[1]+  Stopped    sleep 300

# Resume in background
$ bg %1
[1]+ sleep 300 &

Process Priority Management

Nice Values

Nice values range from -20 (highest priority) to 19 (lowest priority). Default is 0.

  • -20 to -1: High priority (requires root)
  • 0: Default priority
  • 1 to 19: Lower priority (any user can set)

nice - Run command with modified priority

$ nice command          # Run with default nice value (+10)
$ nice -n 10 command    # Run with nice value of 10
$ nice -n -5 command    # Higher priority (requires root)
$ nice -n 19 ./script.sh    # Lowest priority (least CPU)

renice - Change priority of running process

$ renice 10 -p PID      # Set nice value to 10 for process
$ renice -5 -p PID      # Increase priority (requires root)
$ renice 15 -u username # Change priority for user's processes
$ renice 10 -g groupname    # Change priority for group

Example: Running CPU-intensive tasks

# Run video encoding with low priority
$ nice -n 19 ffmpeg -i input.mp4 output.mp4

# Run backup with lower priority
$ nice -n 15 tar -czf backup.tar.gz /data/

# Adjust running process priority
$ renice 10 -p $(pgrep ffmpeg)

Terminal Multiplexers

Terminal multiplexers allow you to manage multiple terminal sessions within a single window and keep sessions running after disconnection. Especially useful for secure remote server management and maintaining persistent sessions.

screen - Manage multiple terminal sessions

$ screen                # Start new screen session
$ screen -S name        # Start named session
$ screen -ls            # List all sessions
$ screen -r             # Reattach to session
$ screen -r name        # Reattach to named session
$ screen -d -r          # Detach and reattach

Common screen commands (press Ctrl+a first):

  • Ctrl+a d - Detach from session
  • Ctrl+a c - Create new window
  • Ctrl+a n - Next window
  • Ctrl+a p - Previous window
  • Ctrl+a k - Kill current window

tmux - Modern terminal multiplexer

$ tmux                  # Start new tmux session
$ tmux new -s name      # Start named session
$ tmux ls               # List all sessions
$ tmux attach           # Attach to last session
$ tmux attach -t name   # Attach to named session
$ tmux kill-session -t name    # Kill session

Common tmux commands (press Ctrl+b first):

  • Ctrl+b d - Detach from session
  • Ctrl+b c - Create new window
  • Ctrl+b n - Next window
  • Ctrl+b p - Previous window
  • Ctrl+b % - Split pane vertically
  • Ctrl+b " - Split pane horizontally

System Monitoring Tools

Complement your process management with our comprehensive VPS system monitoring tools for network diagnostics, performance analysis, and server optimization.

glances - Comprehensive system monitor

$ glances               # Start monitoring
$ glances -t 2          # Update every 2 seconds
$ glances --export-csv file.csv    # Export to CSV

Monitors CPU, memory, network, disk I/O, and processes in one view

gtop - System monitoring dashboard for terminal

$ gtop                  # Beautiful terminal dashboard

Node.js-based system monitor with beautiful graphics

ps_aux - Displays detailed information about all active processes

$ ps aux                # Full process list
$ ps aux --sort=-%cpu   # Sort by CPU usage
$ ps aux --sort=-%mem   # Sort by memory usage

/proc - Virtual filesystem with process information

$ cat /proc/cpuinfo     # CPU information
$ cat /proc/meminfo     # Memory information
$ cat /proc/PID/status  # Process status
$ cat /proc/PID/cmdline # Process command line

Each running process has a directory under /proc with its PID

systemctl - Control systemd system and service manager

$ systemctl status service    # Check service status
$ systemctl start service     # Start service
$ systemctl stop service      # Stop service
$ systemctl restart service   # Restart service
$ systemctl list-units --type=service    # List all services

Essential for managing services like nginx, apache, and containerized applications. For container management, see our Docker cheatsheet. Advanced tips available in our Linux Admin Tips guide.

Process States

Understanding process states helps in diagnosing system behavior and performance issues.

R - Running or Runnable

Process is executing on CPU or waiting in run queue

S - Sleeping (Interruptible)

Waiting for an event or resource, can be interrupted by signals

D - Sleeping (Uninterruptible)

Waiting for I/O, cannot be interrupted (usually disk I/O)

T - Stopped

Process stopped by signal (Ctrl+Z or SIGSTOP)

Z - Zombie (Defunct)

Process terminated but parent hasn't read exit status

I - Idle (Kernel thread)

Idle kernel thread (not contributing to load average)

Additional State Flags

< High-priority process
N Low-priority (nice) process
L Pages locked in memory
s Session leader
l Multi-threaded process
+ Foreground process group

Dealing with Zombie Processes

Zombie processes don't consume resources but indicate parent process issues.

# Find zombie processes
$ ps aux | grep 'Z'

# Find parent of zombie
$ ps -o ppid= -p ZOMBIE_PID

# Kill parent process (if safe)
$ kill PARENT_PID

Master Linux System Administration

Effective process management is crucial for system performance and stability. Explore our VPS benchmarks to find the best hosting for your Linux workloads and applications.