Skip to Content
This project is a work in progress. If you have any questions or suggestions, feel free to contact me.
LinuxSystem AdministrationProcess Management

Process

A process is a program in execution. Every command you run on the terminal spawns at least one process.

Key Identifiers:

  • PID: Process ID – a unique number assigned to each process.
  • PPID: Parent Process ID – ID of the process that spawned it.
  • UID: User ID – the user that owns the process.
  • TTY: Terminal associated (if any).

Types of Processes

TypeDescription
ForegroundTied to the terminal; you interact with it
BackgroundRuns independently of terminal
DaemonLong-running background services (e.g., sshd)
ZombieCompleted execution but still has a PID
OrphanParent process has terminated
Kernel ProcessManaged by the kernel (e.g., kswapd, ksoftirqd)

Process States

StateMeaning
RRunning
SSleeping (interruptible)
DSleeping (uninterruptible)
ZZombie
TStopped (paused)
XDead (shouldn’t appear in normal systems)

Viewing Processes

ps – Process Snapshot

ps aux
OptionDescription
aAll users
uUser-oriented format
xShow processes not attached to terminal

Example output:

USER PID %CPU %MEM COMMAND root 1 0.0 0.1 /sbin/init www-data 1092 0.5 1.2 nginx: worker process

top – Real-time Process Monitoring

top

Press q to quit. Other keys: k to kill, r to renice, P for CPU sort, M for memory sort.

htop – Enhanced Interactive Process Viewer

htop
  • Color-coded
  • Mouse support
  • Tree view (F5)
  • Filter by user (u)

pgrep – Search for Processes by Name

pgrep sshd

Use -l to list with names:

pgrep -l nginx

pidof – Get PID of a Running Program

pidof sshd

pstree – Show Process Hierarchy

pstree -p

Shows nested parent-child relationship.

Managing Processes

kill – Terminate a Process

kill -SIGTERM <PID> # Graceful stop kill -9 <PID> # Forceful kill

Common signals:

  • SIGTERM (15): Request termination
  • SIGKILL (9): Force termination
  • SIGSTOP (19): Pause process
  • SIGCONT (18): Resume process

killall – Kill by Name

killall firefox

nice – Launch Process with Priority

nice -n 10 myscript.sh

Values range from -20 (highest) to 19 (lowest).

renice – Change Priority of a Running Process

renice -n 5 -p 1234

Background & Foreground Jobs

CommandDescription
&Run in background: sleep 100 &
jobsList jobs
fg %1Bring job 1 to foreground
bg %1Resume job 1 in background
Ctrl+ZPause (send to background, stopped)
Ctrl+CKill foreground process

🧾 Metadata of a Process (Example)

ps -p 1234 -o pid,ppid,uid,%cpu,%mem,cmd,start,etime

Shows PID, parent, user, CPU%, memory%, command, start time, elapsed time.

Example Combined Workflow

# Start a long process in the background sleep 500 & # Check it’s running jobs ps aux | grep sleep # Bring it to the foreground fg # Suspend it Ctrl+Z # Resume in background bg # Kill it kill %1

Key Takeaways

  • Every running program is a process with a unique PID
  • Use ps, top, htop, pgrep, pidof to inspect
  • Use kill, killall, nice, renice to manage
  • Processes can be foreground, background, or daemons
Last updated on