Linux Processes and Jobs: A Beginner's Guide
A process is a running program. Linux assigns each process a process ID (PID), and records details such as its owner, parent process, state, and resource use. The shell can also run a job in the background while you continue working.
This guide uses a harmless sleep command as a practice process. Keep the same terminal open while following the steps so the shell can track the job.
Step 1: List Running Processes
View a Process Snapshot
Process BasicsUse ps for a one-time snapshot and top for a live, refreshing view. Press q to leave top. The PID identifies a process; PPID identifies its parent. The example sorts your userβs processes by CPU use. CPU time is accumulated since the process started, not a live percentage.
ps -u "$USER" -o pid,ppid,stat,%cpu,%mem,etime,comm --sort=-%cpu | head -n 15topβ― View Expected Console Output
PID PPID STAT %CPU %MEM ELAPSED COMMAND2184 2101 S 1.2 0.8 02:31 firefox2417 2101 S 0.1 0.2 01:09 bashStep 2: Find a Process by Name and Inspect Its PID
Search for a Process and Read Its Details
Identifypgrep -a searches process names and prints matching command lines. Use the PID from the result to inspect one process with ps. Process names and available details vary by distribution and permissions.
pgrep -a -u "$USER" bash
# Replace 2417 with a PID returned by pgrep.ps -p 2417 -o pid,ppid,user,stat,etime,argsβ― View Expected Console Output
2417 bash PID PPID USER STAT ELAPSED COMMAND 2417 2101 sam S 01:09 bashStep 3: Start and Track a Background Job
Run a Practice Command in the Background
Shell JobsAdd & to start a command in the background. The shell prints a job number and PID. jobs -l shows jobs started by this shell; it is not a system-wide process list. Save the PID in a variable so you can identify this exact practice process later.
sleep 300 &LAB_PID=$!jobs -lps -p "$LAB_PID" -o pid,ppid,stat,etime,argsβ― View Expected Console Output
[1] 3150[1]+ 3150 Running sleep 300 & PID PPID STAT ELAPSED COMMAND 3150 2417 S 00:00 sleep 300Step 4: Stop the Practice Process Cleanly
Send SIGTERM to the PID You Started
Safe ControlWith no signal specified, kill sends SIGTERM, which lets a program handle a clean shutdown. Confirm the PID belongs to the practice command before signaling it. Then wait for the job and check that it has exited.
ps -p "$LAB_PID" -o pid,commkill -TERM "$LAB_PID"wait "$LAB_PID" 2>/dev/null || trueps -p "$LAB_PID" -o pid,commβ― View Expected Console Output
PID COMMAND 3150 sleep PID COMMAND