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
psshows processes associated with the current terminal.ps auxshows a BSD-style table for the system.ps -efshows a full process and parent view.topupdates 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+Zpauses the foreground process.bgresumes it in the background.fgbrings it back to the foreground.
Stop processes
bash
kill PID
kill -TERM PID
kill -KILL PID
pkill process-name
TERMrequests graceful shutdown.KILLstops the process immediately.pkillmatches 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

