Skip to content

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

01

View a Process Snapshot

Process Basics

Use 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.

Terminal window
ps -u "$USER" -o pid,ppid,stat,%cpu,%mem,etime,comm --sort=-%cpu | head -n 15
top
❯ View Expected Console Output
PID PPID STAT %CPU %MEM ELAPSED COMMAND
2184 2101 S 1.2 0.8 02:31 firefox
2417 2101 S 0.1 0.2 01:09 bash

Step 2: Find a Process by Name and Inspect Its PID

02

Search for a Process and Read Its Details

Identify

pgrep -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.

Terminal window
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 bash

Step 3: Start and Track a Background Job

03

Run a Practice Command in the Background

Shell Jobs

Add & 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.

Terminal window
sleep 300 &
LAB_PID=$!
jobs -l
ps -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 300

Step 4: Stop the Practice Process Cleanly

04

Send SIGTERM to the PID You Started

Safe Control

With 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.

Terminal window
ps -p "$LAB_PID" -o pid,comm
kill -TERM "$LAB_PID"
wait "$LAB_PID" 2>/dev/null || true
ps -p "$LAB_PID" -o pid,comm
❯ View Expected Console Output
PID COMMAND
3150 sleep
PID COMMAND

References

Comments