Linux process management — jobs, signals, ps, top, and load

Contents

  1. 1. Process management
    1. 1.1. &
    2. 1.2. ctrl+z
    3. 1.3. bg
    4. 1.4. fg
    5. 1.5. jobs
    6. 1.6. kill
    7. 1.7. nohup
    8. 1.8. ps
    9. 1.9. top
    10. 1.10. nice
    11. 1.11. renice
    12. 1.12. pstree
    13. 1.13. killall
    14. 1.14. free
    15. 1.15. uname
    16. 1.16. uptime
    17. 1.17. netstat
    18. 1.18. dmesg
    19. 1.19. vmstat

Notes from Bird’s Linux Private Kitchen (3rd edition), kept for quick review.

Process management

&

  • Run in the background
  • Stress test (fork bomb): :(){ :|:& };:

ctrl+z

  • Stop the process and push it to the background

bg

  • Resume stopped background jobs

fg

  • Bring jobs to the foreground; the job marked with + is the default
  • fg [%]num — pick a job number
  • fg - — switch to the other job in the rotation

jobs

  • -l — list PIDs with commands
  • -r — running background jobs only
  • -s — stopped background jobs only

kill

  • -l — list signals
  • -SIGHUP # 1: reload
  • -SIGINT # 2: Ctrl+C
  • -SIGKILL # 9: force kill
  • -SIGTERM # 15: polite terminate
  • -SIGSTOP # 17: Ctrl+Z stop
  • kill -SIGKILL %1 — use % for shell job numbers, not PIDs

nohup

  • nohup command — keep running after logout (foreground)
  • nohup command & — same, in the background

ps

  • -A — all processes (same as -e)

  • -a — processes without a controlling terminal

  • -u — processes for effective users

  • -x — with -a, extra detail

  • -l — long listing for your shell jobs, with PIDs

    • F — process flags: 4 = root; 1 = forked child without exec yet
    • S — STAT: R running; S sleeping; D uninterruptible sleep; T stopped; Z zombie
  • -j — job control format

  • -f — fuller output

  • aux — everything (note: no leading dash)

  • axjf — process tree; like pstree

  • -lA — same idea

top

  • -d seconds — refresh interval (default 5s)
  • -bn num — batch mode for num iterations
  • -p — filter by PID

Interactive keys

  • ? help
  • P sort by CPU
  • M sort by memory
  • N sort by PID
  • T sort by CPU time (TIME+)
  • k send a signal to a PID
  • r change nice value
    • PRI(new) = PRI(old) + nice; lower PRI wins; root nice range -20..19, others 0..19

nice

  • n num — start with a given nice value

renice

  • renice num PID — retune a running process
  • Nice values inherit parent → child

pstree

  • -A — ASCII connectors
  • -U — Unicode connectors
  • -p — show PIDs
  • -u — show owning user

killall

  • -i — interactive confirm
  • -e — exact command name
  • -I — case-insensitive match

free

  • -b bytes; m MB; k KB; g GB
  • -t — show RAM plus swap totals

uname

  • -a — all fields
  • -s — kernel name
  • -r — kernel release
  • -m — machine hardware
  • -p — CPU type
  • -i — hardware platform

uptime

  • Boot time and 1/5/15-minute load averages

netstat

  • -a — all connections, listeners, and sockets
  • -t — TCP
  • -u — UDP
  • -n — numeric host/port (skip name lookup)
  • -l — listening sockets only
  • -p — owning PID
  • netstat -tlnp — listeners with PID
    • grep 'rsync' /etc/services — map service to port

dmesg

  • Kernel ring buffer from boot
  • dmesg | more — page through it

vmstat

  • -a — active/inactive instead of buffer/cache line
  • -f — forks since boot
  • -S unit (K,M) — output unit
  • -d — disk read/write totals
  • -p — per-partition disk stats
  • vmstat 1 3 — sample every 1s, three times
Questions? Leave a comment below or email: newbvirgil@gmail.com