#Why this matters
In the previous lesson, you saw how a CPU executes bytes from RAM. If every program could freely touch physical RAM and storage hardware, a single buggy or malicious script could read another program's secrets or crash the system.
An operating system (OS) prevents this by isolating each running program. For defenders, inspecting running processes is one of the fastest ways to spot rogue scripts, unauthorised shells, and malware pretending to be legitimate services.
#Kernel space, user space, and system calls
At the core of an OS sits the kernel, the privileged software loaded at boot. Modern CPUs enforce hardware privilege levels (such as Ring 0 for kernel mode and Ring 3 for user mode on x86):
- Kernel space controls CPU scheduling, RAM allocation, disks, network interfaces, and permission checks.
- User space holds everyday apps such as browsers, editors, and web servers, which cannot directly touch hardware or another process's memory.
When a user-space program needs to read a file or open a network socket, it makes a system call (syscall) such as openat or read. The CPU switches to kernel mode, the kernel checks permissions, performs the work, and returns the result safely.
#Program vs. process and virtual memory
A program is a passive file on disk (like /usr/bin/python3 or notepad.exe). A process is an active instance running in RAM; launching the same program three times creates three separate processes.
The OS gives each process virtual memory, so every program sees its own private address space while the kernel maps those addresses to physical RAM. To run many processes on fewer CPU cores, the kernel performs rapid context switches: it pauses one process, saves its CPU registers (including the instruction pointer), loads another's registers, and resumes.
| Attribute | Meaning | Why analysts check it |
|---|---|---|
PID |
Unique numeric Process ID | Identifies the exact instance for logs or termination |
PPID |
Parent Process ID | Reveals which process launched it |
USER / Owner |
Account running the process | Shows low-privilege user vs. root or SYSTEM |
COMMAND / Path |
Executable path and arguments | Exposes flags or binaries faking trusted names |
STAT |
State (R running, S sleeping, Z zombie) |
Highlights stuck or orphaned processes |
#Process trees and parent-child relationships
At boot, the kernel starts an initial user-space process at PID 1 (usually systemd on modern Linux). Every other process is spawned by an existing parent, forming a process tree. Normal apps follow predictable chains: a terminal spawns bash, which runs ls. By contrast, a web server or PDF reader spawning /bin/sh or powershell.exe signals command injection or a malicious document.
#Inspecting processes with ps, htop, and Task Manager
On Linux, ps prints a process snapshot. Adding --forest indents children under their parents so unusual branches stand out at a glance.
$ ps -eo pid,ppid,user,stat,comm --forest
PID PPID USER STAT COMMAND
1 0 root Ss systemd
812 1 root Ss \_ sshd
1045 812 analyst Ss \_ sshd
1046 1045 analyst Ss \_ bash
1190 1046 analyst R+ \_ ps
920 1 root Ss \_ nginx
921 920 www-data S \_ nginx
1204 921 www-data S \_ sh
1205 1204 www-data S \_ sleepPID 1204 (sh) has PPID 921, an nginx worker owned by www-data - web servers should not spawn interactive shells. For live monitoring, htop updates continuously; press F5 (or t) to toggle tree view and F4 to filter by name.
On Windows, open Task Manager (Ctrl+Shift+Esc), click More details, and check the Details tab. Enable the PID, User name, and Command line columns to inspect both ownership and the exact launch path.
#Common mistakes
- Trusting process names alone: Attackers rename binaries to
sshdorsvchost.exe; always verify the full disk path, arguments, andPPID. - Running daily tools as
rootor Administrator: Elevated privileges bypass user isolation if an application is compromised. - Missing short-lived processes:
psandhtoponly show processes alive at that instant; persistent logs are needed for fast commands. - Killing only the child: Stopping
1205(sleep) while leaving a malicious parent1204(sh) or vulnerable service alive lets it respawn.
#Summary
- The OS kernel runs in privileged kernel space and mediates hardware and memory access via system calls.
- A process is an active instance of a program with virtual memory,
PID,PPID, owner, and register state swapped during context switches. - Process trees expose parent-child lineage, making unexpected shells or launchers easy to spot.
- Use
ps --forest,htop(F5), and Task Manager's Details tab to inspect paths, ownership, and hierarchy.