Objective

View, control, and manage Linux processes: understand process states, send signals, manage foreground/background jobs, and set priorities.

Tools & Technologies

  • ps
  • top
  • htop
  • kill
  • jobs
  • fg
  • bg
  • nohup
  • nice

Key Commands

ps aux | grep nginx
kill -15 PID
jobs && fg %1
nohup script.sh &
nice -n 10 cmd
renice -n 5 -p PID

Architecture Overview

stateDiagram-v2 [*] --> Running: process starts Running --> Sleeping: waiting for I/O Sleeping --> Running: I/O ready Running --> Stopped: SIGSTOP / Ctrl+Z Stopped --> Running: SIGCONT / fg Running --> Zombie: exits, parent not waited Zombie --> [*]: parent calls wait() Running --> [*]: SIGKILL / exit()

Step-by-Step Process

01
View Processes

Use ps and top to see what's running. ps is a snapshot; top is live.

ps aux          # all processes, BSD style
ps -ef          # all processes, UNIX style
ps aux | grep nginx
top             # live view (q to quit)
htop            # better top (F10 to quit)
pgrep nginx     # PIDs by name
02
Send Signals

Signals are messages sent to processes. SIGTERM (15) requests graceful exit. SIGKILL (9) forces immediate termination.

# By PID
kill PID          # sends SIGTERM (15)
kill -9 PID       # SIGKILL — cannot be caught
kill -1 PID       # SIGHUP — reload config

# By name
killall nginx
pkill -f 'python script'

# List all signals
kill -l
03
Background Jobs

Run commands in the background and manage them with the job control system.

long_command &      # start in background
jobs                # list jobs
fg %1               # bring job 1 to foreground
bg %2               # resume job 2 in background
Ctrl+Z              # suspend current job
Ctrl+C              # terminate current job
04
nohup & nice

nohup keeps a process running after logout. nice sets the scheduling priority.

nohup ./backup.sh > backup.log 2>&1 &
# Process continues after terminal closes

nice -n 10 make         # lower priority (0=normal, 19=lowest)
nice -n -5 critical     # higher priority (needs root for negative)
renice -n 5 -p 1234    # change running process priority

Challenges & Solutions

  • SIGKILL cannot be caught or ignored — last resort only
  • Zombie processes are harmless but indicate a parent not calling wait()

Key Takeaways

  • Always try SIGTERM before SIGKILL — give processes a chance to clean up
  • nohup + & is the simple alternative to running a proper systemd service