SkillSprout
Chapter 1 · Lesson 6
Beginner
1 min read

Processes and Background Jobs

Overview

A process is a running instance of a program. Every process has a PID, a parent process, a state and resource usage. A shell can run processes in the foreground or background and later stop or resume them.

Detailed Notes

List processes

bash
ps
ps aux
ps -ef
top
  • ps shows processes associated with the current terminal.
  • ps aux shows a BSD-style table for the system.
  • ps -ef shows a full process and parent view.
  • top updates CPU and memory usage interactively.

The PID is the process identity. The parent PID identifies the process that started it.

Foreground and background

bash
sleep 30

This blocks the foreground shell for 30 seconds. Interrupt it with Ctrl+C.

Start it in the background:

bash
sleep 30 &
jobs
ps

& starts a process without waiting for it in the foreground. jobs lists jobs owned by the current shell.

Move a job:

bash
fg %1
Ctrl+Z
bg %1
  • Ctrl+Z pauses the foreground process.
  • bg resumes it in the background.
  • fg brings it back to the foreground.

Stop processes

bash
kill PID
kill -TERM PID
kill -KILL PID
pkill process-name
  • TERM requests graceful shutdown.
  • KILL stops the process immediately.
  • pkill matches process names and can affect multiple processes.

Prefer PID-specific kill over broad process-name matching.

Common Interview Questions

Finished this lesson?

0 of 25 lessons done · 0% of the course