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
Type | Description |
---|---|
Foreground | Tied to the terminal; you interact with it |
Background | Runs independently of terminal |
Daemon | Long-running background services (e.g., sshd) |
Zombie | Completed execution but still has a PID |
Orphan | Parent process has terminated |
Kernel Process | Managed by the kernel (e.g., kswapd, ksoftirqd) |
Process States
State | Meaning |
---|---|
R | Running |
S | Sleeping (interruptible) |
D | Sleeping (uninterruptible) |
Z | Zombie |
T | Stopped (paused) |
X | Dead (shouldn’t appear in normal systems) |
Viewing Processes
ps
– Process Snapshot
ps aux
Option | Description |
---|---|
a | All users |
u | User-oriented format |
x | Show 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 terminationSIGKILL
(9): Force terminationSIGSTOP
(19): Pause processSIGCONT
(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
Command | Description |
---|---|
& | Run in background: sleep 100 & |
jobs | List jobs |
fg %1 | Bring job 1 to foreground |
bg %1 | Resume job 1 in background |
Ctrl+Z | Pause (send to background, stopped) |
Ctrl+C | Kill 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