Course: From Basic Science to Web Hosting
Module 04 — Operating Systems
What Really Happens When You Run a Linux Command?
Difficulty: Beginner → Intermediate
Prerequisites: Lesson 015 — What Is an Operating System?
Estimated time: 30 minutes
We will use a real command you have already encountered:
sudo systemctl restart nginx
The goal is to understand what happens from your keyboard to the CPU, through Linux, to Nginx.
1. Start at the Beginning
You see:
$ sudo systemctl restart nginx
It looks like one command.
But underneath, many layers are involved:
Keyboard
↓
Terminal
↓
Shell
↓
Command
↓
Program
↓
System calls
↓
Linux kernel
↓
systemd
↓
Nginx
And underneath all of that:
CPU
RAM
Storage
Electronic circuits
Transistors
2. What Is a Terminal?
A terminal provides an interface through which you can interact with the operating system using text.
For example:
ubuntu@server:~$
You type:
ls
The terminal receives your keyboard input.
Conceptually:
Keyboard
↓
Terminal
↓
Text input
3. What Is a Shell?
The terminal itself isn’t normally responsible for interpreting shell commands.
A shell is a program that interprets commands.
Common shells include:
bash
zsh
sh
fish
Ubuntu commonly uses Bash by default in many environments.
So:
Keyboard
↓
Terminal
↓
Bash
4. Shell Prompt
When you see something like:
ubuntu@server:~$
the shell is effectively saying:
I am ready to receive a command.
You type:
ls
The shell reads it.
5. The Shell Parses the Command
Suppose you type:
sudo systemctl restart nginx
The shell separates the command into components roughly like:
sudo
systemctl
restart
nginx
These have different roles.
6. First Word: sudo
sudo is a program that allows an authorized user to run a command with elevated privileges.
So:
sudo systemctl restart nginx
is conceptually:
Run systemctl
↓
with elevated privileges
The exact authorization process depends on the system’s sudo configuration.
7. Second Word: systemctl
systemctl is a command-line program used to communicate with systemd.
So:
systemctl
is not the service manager itself.
It is a client/control program.
Conceptually:
You
↓
systemctl
↓
systemd
8. Third Word: restart
This is an argument telling systemctl what operation you want.
restart
means:
Stop/restart the specified service
9. Fourth Word: nginx
This identifies the service unit.
nginx
So the whole request is approximately:
sudo
↓
run systemctl with elevated privileges
systemctl
↓
talk to systemd
restart
↓
requested operation
nginx
↓
target service
10. What Happens Next?
The sudo program performs its authorization work and then executes the requested command with the appropriate credentials.
Then:
systemctl
↓
communicates with
↓
systemd
On a system using systemd, this communication is typically performed through system mechanisms such as Unix-domain sockets and the D-Bus/systemd management interfaces.
You don’t need to manually implement any of this.
The OS handles it.
11. What Is systemd?
systemd is a system and service manager.
It manages units such as:
Services
Sockets
Mounts
Timers
Targets
For our example:
nginx.service
is a service unit.
12. systemd Checks the Service
When you request:
systemctl restart nginx
systemd determines how the Nginx service should be managed based on its unit configuration.
Conceptually:
systemctl
↓
systemd
↓
nginx.service
13. Where Does the Service Configuration Come From?
Systemd unit files can exist in locations such as:
/etc/systemd/system/
and distribution/package-managed locations such as:
/usr/lib/systemd/system/
The exact locations and precedence depend on the system.
A service unit can describe things such as:
Service name
Dependencies
Command to start
Command to stop
Restart behavior
User
Environment
14. systemd Starts Nginx
Eventually systemd launches the Nginx process according to the service configuration.
Conceptually:
systemd
↓
fork/exec and process management
↓
Nginx
The kernel is involved in creating and managing the process.
15. What Is exec?
Unix-like systems have system calls that allow a process to replace its current program image with another executable.
A family of functions commonly called exec* is used for this purpose.
Conceptually:
Existing process
↓
exec()
↓
New program image
This is one of the fundamental mechanisms behind launching programs.
16. What Is a System Call?
Applications cannot directly perform arbitrary privileged hardware operations.
Instead, they request services from the kernel through:
System calls
Conceptually:
Application
↓
System call
↓
Linux kernel
↓
Hardware / kernel-managed resources
Examples include operations related to:
Files
Processes
Memory
Networking
Time
Devices
17. User Space and Kernel Space
Linux separates normal application execution from privileged kernel execution.
Conceptually:
┌───────────────────────────┐
│ USER SPACE │
│ │
│ Bash │
│ sudo │
│ systemctl │
│ Nginx │
│ PHP │
│ MySQL │
└─────────────┬─────────────┘
│
System calls
│
┌─────────────▼─────────────┐
│ KERNEL SPACE │
│ │
│ Process management │
│ Memory management │
│ Networking │
│ Filesystems │
│ Device drivers │
└─────────────┬─────────────┘
│
┌─────────────▼─────────────┐
│ HARDWARE │
│ CPU / RAM / SSD / NIC │
└───────────────────────────┘
This separation is fundamental to operating-system design.
18. Why Can’t Nginx Just Control the Hardware?
Security and stability.
Imagine every application could directly control:
RAM
SSD
Network hardware
CPU control mechanisms
One buggy program could potentially destroy the system.
Instead:
Application
↓
Kernel
↓
Controlled access
↓
Hardware
The kernel acts as a privileged resource manager.
19. What Happens Inside the CPU?
At the hardware level, the CPU executes machine instructions.
Conceptually:
Machine instruction
↓
CPU fetch
↓
Decode
↓
Execute
↓
Memory/register operations
And physically:
CPU instructions
↓
Transistor switching
↓
Electrical signals
So even:
systemctl restart nginx
eventually becomes processor activity.
20. What Happens in RAM?
Programs need memory.
For example:
Bash
sudo
systemctl
systemd
Nginx
all require memory while executing.
Conceptually:
SSD
↓
Program executable
↓
Linux loads program
↓
RAM
↓
CPU executes instructions
21. What Happens on the SSD?
Programs and configuration files are stored persistently.
For example:
/usr/bin/systemctl
/usr/bin/sudo
/usr/sbin/nginx
/etc/nginx/
/etc/systemd/
When required, executable code and data are loaded from storage into memory.
Simplified:
SSD
↓
Filesystem
↓
Executable/data
↓
RAM
↓
CPU
22. What Happens to Nginx?
After systemd successfully starts or restarts Nginx:
Nginx process
↓
Loads configuration
↓
Opens required resources
↓
Creates/listens on sockets
↓
Waits for network requests
For HTTPS, it may listen on:
TCP 443
For HTTP:
TCP 80
23. Your Website Request
Now suppose someone opens:
https://templates.cresignsys.com
The path becomes:
Browser
↓
DNS
↓
IP address
↓
Internet
↓
Server
↓
TCP connection
↓
TLS connection
↓
Nginx
Nginx then processes the HTTP request.
24. Where Does TLS Fit?
Your SSL/TLS certificate belongs here:
Internet
↓
TCP
↓
TLS
↓
HTTP
↓
Nginx
More precisely, modern HTTPS normally uses:
HTTP
over
TLS
over
TCP
over
IP
Although HTTP/3 uses QUIC rather than TCP, which changes the transport layer.
For your current Nginx setup, HTTPS is commonly TCP + TLS + HTTP/1.1 or HTTP/2.
25. Nginx Reads the Request
Suppose the browser requests:
GET /
Nginx examines:
Hostname
Path
Method
Headers
TLS connection
For example:
Host: templates.cresignsys.com
Nginx uses its configuration to determine what should happen.
26. Nginx May Serve a Static File
If the request is for:
style.css
Nginx can directly read the file.
Conceptually:
Browser
↓
Nginx
↓
Filesystem
↓
style.css
↓
Nginx
↓
Browser
27. Nginx May Send the Request to PHP
If WordPress needs PHP processing:
Browser
↓
Nginx
↓
PHP-FPM
↓
WordPress
PHP-FPM executes the PHP application logic.
28. WordPress May Query MySQL
For dynamic content:
WordPress
↓
Database query
↓
MySQL
↓
Database result
↓
WordPress
Then:
WordPress
↓
HTML generation
↓
PHP-FPM
↓
Nginx
↓
TLS
↓
Internet
↓
Browser
29. One Browser Request — Full Journey
Here is the complete path:
USER
│
│ enters URL
▼
BROWSER
│
▼
DNS
│
▼
IP ADDRESS
│
▼
INTERNET
│
▼
SERVER NIC
│
▼
LINUX NETWORK STACK
│
▼
TCP
│
▼
TLS
│
▼
NGINX
│
├──── static file ────► FILESYSTEM
│
└──── dynamic request ─► PHP-FPM
│
▼
WORDPRESS
│
▼
MYSQL
│
▼
HTML RESPONSE
│
▼
NGINX
│
▼
TLS
│
▼
BROWSER
30. The Most Important Layering Concept
Don’t think of the server as one program.
Think of it as layers:
Layer 1
Physical hardware
Layer 2
Firmware
Layer 3
Linux kernel
Layer 4
System services
Layer 5
Network stack
Layer 6
TLS
Layer 7
Web server
Layer 8
Application runtime
Layer 9
Application
Layer 10
Database
Each layer depends on lower layers.
31. Why This Matters for Troubleshooting
Suppose your website doesn’t open.
Don’t immediately assume:
“WordPress is broken.”
There are many possible layers:
DNS
↓
IP
↓
Firewall
↓
Network
↓
TCP
↓
TLS
↓
Nginx
↓
PHP
↓
WordPress
↓
MySQL
The correct troubleshooting method is:
Find the lowest layer that is failing, then move upward.
32. Example
If:
systemctl status nginx
shows Nginx is stopped, don’t troubleshoot WordPress first.
Check:
Hardware
↓
Linux
↓
systemd
↓
Nginx
Only after Nginx works should you move upward.
33. Your Current Learning Position
You started from:
Atom
and reached:
Linux command
The complete path is:
Atom
↓
Electron
↓
Charge
↓
Electricity
↓
Circuit
↓
Semiconductor
↓
Transistor
↓
Logic
↓
Binary
↓
CPU
↓
Computer
↓
Operating System
↓
Linux
↓
Command
Now we can begin going deeper into Linux itself.
34. Next Lesson — 017
What Is the Linux Filesystem?
We will start from the absolute foundation:
/
├── bin
├── boot
├── dev
├── etc
├── home
├── lib
├── media
├── mnt
├── opt
├── proc
├── root
├── run
├── sbin
├── srv
├── sys
├── tmp
├── usr
├── var
└── storage
We will learn what every directory actually means, why /etc contains configuration, why /var contains changing data, what /proc and /sys really are, and how your:
/storage/websites/
fits into the Linux architecture.
After that we can progress systematically through:
Linux filesystem → users → permissions → processes → services → networking → DNS → TCP/IP → TLS → Nginx → PHP-FPM → MySQL → WordPress → web hosting.