Linux Processes โ Deep Basics
We now go one level deeper into the Ubuntu server.
Previously:
Hardware
โ
Linux Kernel
โ
Processes
โ
Services
โ
Nginx / PHP-FPM / MySQL
Now we answer:
What exactly is a process, how does Linux run it, and what happens when many users access your website simultaneously?
1. Program vs Process
These two words are different.
Program
A program is stored code.
Example:
/usr/sbin/nginx
It exists on storage.
Process
When that program is executed:
nginx executable
โ
Linux loads it
โ
Process
The process exists in memory and is actively running.
So:
Program
=
stored instructions
Process
=
running instance of those instructions
2. Simple Example
When you run:
ls
Linux finds the ls program and executes it.
Conceptually:
ls program
โ
process created
โ
CPU executes instructions
โ
output
โ
process exits
Nginx is different because it normally remains running.
3. Long-Running Process
Nginx:
Start
โ
Keep running
โ
Wait for requests
โ
Process requests
โ
Continue running
Similarly:
MySQL
PHP-FPM
SSH
are normally long-running services.
4. PID
Every running process receives a:
Process ID
or:
PID
For example:
PID 1
PID 100
PID 245
PID 1842
Run:
ps aux
and you’ll see process IDs.
5. PID 1
On your Ubuntu system, PID 1 is normally:
systemd
Conceptually:
Kernel
โ
systemd
โ
services
โ
processes
PID 1 has a particularly important role in the userspace system.
6. Parent Process
Processes can have relationships.
A process can create another process.
Conceptually:
Parent
โ
โโโ Child
โโโ Child
โโโ Child
The operating system maintains parent/child relationships.
7. PPID
A process also has a:
Parent Process ID
or:
PPID
You can inspect this with commands such as:
ps -ef
You’ll see both:
PID
PPID
8. Example
Conceptually:
systemd
PID 1
โ
โผ
nginx
PID 1000
PPID 1
Then Nginx may create workers:
nginx master
PID 1000
โ
โโโ worker PID 1001
โโโ worker PID 1002
โโโ worker PID 1003
The exact process model depends on Nginx configuration and startup environment.
9. Nginx Master and Workers
Nginx commonly uses:
Master process
โ
โโโ Worker
โโโ Worker
โโโ Worker
โโโ Worker
The master handles management tasks.
Workers handle connections and requests.
10. Why Multiple Workers?
Suppose your server has multiple CPU cores.
You don’t necessarily want one process handling everything.
Multiple workers can handle connections concurrently.
Conceptually:
Nginx
โ
โโโโโโโโโผโโโโโโโโ
โผ โผ โผ
Worker Worker Worker
11. Worker Processes
A worker can handle many connections depending on configuration and workload.
This is important:
One worker does not necessarily equal one visitor.
You could have:
4 workers
1000 connections
The workers can handle many connections using event-driven I/O.
12. Event-Driven Architecture
Nginx is designed around an event-driven model.
Instead of:
1 connection
โ
1 permanently occupied process
Nginx can efficiently manage many connections with a smaller number of worker processes.
Conceptually:
Worker
โ
โโโ Connection A
โโโ Connection B
โโโ Connection C
โโโ Connection D
โโโ ...
This is one reason Nginx is efficient for handling large numbers of connections.
13. PHP-FPM Is Different
PHP-FPM commonly uses a pool of PHP worker processes.
Conceptually:
PHP-FPM
โ
โโโ PHP Worker 1
โโโ PHP Worker 2
โโโ PHP Worker 3
โโโ PHP Worker 4
When Nginx needs PHP:
Nginx
โ
PHP-FPM
โ
available worker
โ
PHP execution
14. Why PHP Workers Matter
Suppose:
10 visitors
request dynamic WordPress pages simultaneously.
PHP-FPM needs enough worker capacity to process requests concurrently.
If all workers are busy:
Request
โ
PHP-FPM
โ
No available worker
โ
Wait
This can increase response time.
15. PHP-FPM Worker Pool
PHP-FPM can be configured with process-management modes such as:
static
dynamic
ondemand
These control how PHP worker processes are created and managed.
We will study these in detail later.
16. MySQL Process
MySQL is also a long-running service.
Conceptually:
systemd
โ
mysqld
โ
database engine
The MySQL server manages:
Connections
Queries
Memory
Tables
Indexes
Transactions
Storage
17. One WordPress Request
Now look at one request again:
Browser
โ
Nginx worker
โ
PHP-FPM worker
โ
WordPress
โ
MySQL
Several processes may participate in one request.
18. Many Requests
Suppose 20 users visit simultaneously:
Nginx
โ
โโโโโโโโโโโโโโผโโโโโโโโโโโโโ
โผ โผ โผ
Worker 1 Worker 2 Worker 3
โ โ โ
โโโโโโโโโโโโโโผโโโโโโโโโโโโโ
โผ
PHP-FPM
โโโโโโโโผโโโโโโโ
โผ โผ โผ
PHP 1 PHP 2 PHP 3
โ
โผ
MySQL
This is a simplified representation, but it shows the relationship.
19. CPU Scheduling
The CPU cannot literally execute an unlimited number of instructions simultaneously on one core.
Linux uses scheduling.
Conceptually:
Process A
Process B
Process C
Process D
โ
CPU scheduler
โ
CPU cores
The kernel decides which runnable tasks receive CPU time.
20. Context Switching
Suppose the CPU is executing:
Process A
and then switches to:
Process B
Linux saves/restores execution state.
This is called:
Context switching
Conceptually:
CPU
โ
Process A
โ
save state
โ
Process B
โ
execute
Context switching has overhead, so having huge numbers of processes is not automatically better.
21. Threads
A process can contain multiple:
Threads
Conceptually:
Process
โโโ Thread 1
โโโ Thread 2
โโโ Thread 3
Threads share many resources within their process.
The exact relationship between Linux tasks, threads, and processes is more nuanced, but this model is useful initially.
22. Process vs Thread
Simplified:
Process
=
independent execution environment
Thread
=
execution path within a process
Threads within a process can share memory.
This makes communication efficient but also introduces synchronization challenges.
23. Nginx and Threads
Nginx’s common architecture is heavily based on processes and event-driven workers rather than creating one thread per connection.
This is different from some other server architectures.
24. PHP and Threads
PHP-FPM generally uses separate worker processes rather than requiring a large multithreaded PHP execution model.
Conceptually:
PHP-FPM
โ
multiple worker processes
This gives process isolation between workers.
25. Process States
Linux processes can have different states.
You may encounter:
R
S
D
T
Z
The exact state meanings can be inspected through tools such as ps.
26. R โ Running/Runnable
R represents a process that is running or runnable.
Conceptually:
Process
โ
ready to execute
It may be actively executing or waiting to be scheduled.
27. S โ Sleeping
A sleeping process is waiting for an event.
For example:
Nginx worker
โ
waiting for network activity
This is normal.
A sleeping process isn’t necessarily broken.
28. D โ Uninterruptible Sleep
D commonly indicates waiting in an uninterruptible kernel wait, often associated with I/O.
For example:
Process
โ
waiting for storage/network-related kernel operation
A large number of persistent D processes can indicate an underlying problem.
29. T โ Stopped/Traced
A process can be stopped or traced.
For example, debugging tools can stop processes.
30. Z โ Zombie
A zombie process is a process that has finished execution but whose parent has not yet collected its exit status.
Conceptually:
Child
โ
finishes
โ
Zombie
โ
Parent collects status
โ
removed
A small number of transient zombies can be normal.
Persistent large numbers can indicate a parent-process management problem.
31. Zombie Does Not Mean Running
A zombie process is:
finished execution
It is not actively consuming CPU like a normal running process.
It mainly remains as a process-table entry until its parent handles it.
32. Inspect Process States
You can use:
ps -eo pid,ppid,user,stat,comm
This gives a useful view of:
PID
PPID
USER
STATE
COMMAND
33. Process Tree
Try:
pstree -p
if available.
You may see something conceptually like:
systemd(1)
โโsshd(...)
โโnginx(...)
โ โโnginx(...)
โ โโnginx(...)
โโphp-fpm(...)
โ โโphp-fpm(...)
โ โโphp-fpm(...)
โโmysqld(...)
This is very useful when learning server architecture.
34. CPU Usage
Use:
top
You’ll see processes and CPU usage.
Conceptually:
PID
USER
CPU%
MEM%
COMMAND
35. Memory Usage
top also helps identify processes consuming significant memory.
For example:
php-fpm
mysqld
nginx
may have very different memory footprints.
36. Why PHP Can Consume a Lot of RAM
A PHP worker may load:
WordPress core
Plugins
Theme
Libraries
Application data
into memory.
A complex WordPress request can therefore consume considerably more memory than a simple static file request.
37. Static vs Dynamic Resource Cost
Compare:
Static
GET /logo.png
โ
Nginx
โ
disk/cache
โ
response
Dynamic
GET /article/
โ
Nginx
โ
PHP-FPM
โ
WordPress
โ
Plugins
โ
MySQL
โ
Theme
โ
HTML
Dynamic requests generally involve more computation.
38. Why Caching Is Powerful
Suppose the result of:
GET /article/
is cached.
Instead of:
Nginx
โ
PHP
โ
WordPress
โ
MySQL
the request might become:
Nginx
โ
Cache
โ
Response
This can dramatically reduce application work.
39. CPU Bottleneck
If CPU becomes saturated:
CPU
โ
100%
requests may take longer.
Possible symptoms:
Slow website
Slow PHP
Slow MySQL
High load
Timeouts
But high CPU does not automatically identify the root cause.
40. Memory Bottleneck
If available memory becomes very low:
RAM
โ
pressure
Linux may use swap and/or processes may encounter allocation problems.
Performance can degrade substantially.
41. Swap
Swap is disk-backed space used by the operating system as part of its virtual memory system.
Conceptually:
RAM
โ
memory pressure
โ
some pages may be moved/reclaimed
โ
swap/storage
Swap is much slower than RAM.
It is not a replacement for sufficient RAM.
42. Why Your Server Needs Monitoring
A hosting server should be watched for:
CPU
RAM
Swap
Disk
Disk I/O
Network
Processes
Connections
PHP-FPM workers
MySQL load
Nginx errors
This becomes the foundation of server monitoring.
43. Process Limits
Linux can impose limits on resources such as:
Open files
Processes
Memory
CPU
You can inspect shell limits with:
ulimit -a
Some limits can affect high-traffic applications.
44. File Descriptors
A process may need file descriptors for:
Files
TCP sockets
Unix sockets
Pipes
Other I/O resources
A busy Nginx server can have many open sockets.
Therefore:
Traffic
โ
Connections
โ
Sockets
โ
File descriptors
can become a scaling consideration.
45. Nginx Connection Capacity
If Nginx is configured for a certain number of worker connections, that becomes part of its capacity planning.
The actual effective maximum is influenced by:
worker_processes
worker_connections
file descriptor limits
CPU
memory
network
application latency
So worker_connections is not simply “the number of users the server supports.”
46. PHP-FPM Capacity
PHP-FPM has another important constraint:
Maximum simultaneous PHP workers
Suppose you have:
10 PHP workers
and:
50 dynamic requests
The first group can be processed while others may wait, depending on queue/backlog behavior.
47. The Bottleneck Principle
A web application can be limited by:
DNS
Network
CPU
RAM
Disk I/O
Nginx
PHP-FPM
MySQL
External API
The slowest constrained component can become the bottleneck.
48. Example
Suppose:
CPU: 20%
RAM: 40%
Disk: normal
Nginx: normal
PHP-FPM: 100% workers busy
MySQL: normal
The likely immediate bottleneck is:
PHP-FPM capacity
Increasing CPU alone may not solve the problem.
49. Another Example
Suppose:
CPU: 30%
RAM: 40%
PHP-FPM: normal
MySQL: very slow
Then the application can still be slow because:
WordPress
โ
MySQL query
โ
slow
The server doesn’t need more PHP workers to solve a database bottleneck.
50. Another Example
Suppose:
CPU: 100%
PHP-FPM: busy
MySQL: busy
The first question becomes:
Which process is consuming CPU?
Run:
top
Then investigate the process and workload.
51. Signals
Linux can communicate with processes using:
Signals
Examples include:
SIGTERM
SIGKILL
SIGHUP
SIGINT
These have different semantics.
52. SIGTERM
SIGTERM is generally a request to terminate gracefully.
Conceptually:
system/service manager
โ
SIGTERM
โ
process
โ
clean shutdown
It gives the application an opportunity to clean up.
53. SIGKILL
SIGKILL forcibly terminates a process.
It cannot be caught or handled by the target process.
This is why it should not be the first choice for normal service management.
Prefer graceful service management whenever possible.
54. SIGHUP
Historically associated with terminal hangups, but many Unix daemons use it for configuration reload behavior.
For example, some services interpret SIGHUP as:
Reload configuration
The exact behavior is application-specific.
55. Why systemctl Is Better Than Random Signals
Instead of manually killing Nginx processes:
systemctl reload nginx
or:
systemctl restart nginx
lets systemd and the service’s unit configuration manage the operation properly.
This is safer and more predictable.
56. Nginx Graceful Reload
Nginx is designed to support configuration reloads with minimal disruption.
Typical workflow:
Edit config
โ
nginx -t
โ
systemctl reload nginx
This is an excellent production habit.
57. Process Monitoring
Useful commands:
ps aux
top
pstree -p
systemctl status nginx
systemctl status mysql
58. Find Nginx Processes
You can use:
ps aux | grep nginx
But remember that grep nginx itself can appear in the results.
A cleaner approach is often:
pgrep -a nginx
59. Find PHP-FPM
Depending on your PHP version:
pgrep -a php-fpm
or:
ps aux | grep php-fpm
60. Find MySQL
pgrep -a mysqld
Again, the exact process name can vary by installation.
61. A Real Request and Processes
Let’s put the entire lesson together.
User requests:
GET /
Then:
Nginx worker
โ
PHP-FPM worker
โ
WordPress
โ
MySQL
The kernel manages:
CPU
RAM
Sockets
Files
Scheduling
while systemd manages the long-running services.
62. Complete Linux Stack
USER
โ
โผ
BROWSER
โ
โผ
HTTP
โ
โผ
NGINX
โ
โโโโโโโดโโโโโโ
โผ โผ
Static files PHP-FPM
โ
โผ
WordPress
โ
โโโโโโโโดโโโโโโโ
โผ โผ
Filesystem MySQL
โ โ
โโโโโโโโฌโโโโโโโ
โผ
RESPONSE
โ
โผ
NGINX
โ
โผ
NETWORK
โ
โผ
LINUX KERNEL
โโโโโโโโผโโโโโโโ
โผ โผ โผ
CPU RAM Storage
63. The Most Important Concepts Today
Remember these distinctions:
Program
=
stored code
Process
=
running program
PID
=
process identifier
PPID
=
parent process identifier
Thread
=
execution path inside a process
Socket
=
communication endpoint
File descriptor
=
process handle for I/O resources
Service
=
managed long-running system component
systemd
=
service/process management framework
64. How This Helps Your Hosting Platform
When you eventually create a hosting dashboard, you could expose information such as:
Server Status
โโโโโโโโโโโโโ
CPU 22%
RAM 48%
Disk 37%
Nginx Running
PHP-FPM Running
MySQL Running
SSL Valid
Behind that simple dashboard are Linux commands and service APIs.
For example:
Dashboard
โ
Monitoring logic
โ
Linux/systemd
โ
Processes
โ
Metrics
65. The Next Layer: Virtual Memory
We have discussed:
CPU
RAM
Processes
Threads
but we haven’t yet explained something fundamental:
How can dozens or hundreds of processes each behave as if they have their own memory?
The answer is:
Virtual Memory
The next lesson will go deep into:
Physical RAM
โ
Virtual address
โ
Process address space
โ
Pages
โ
Page tables
โ
MMU
โ
TLB
โ
Physical memory
โ
Swap
Then we will connect it to:
Nginx memory
PHP-FPM memory
MySQL memory
WordPress memory
and understand why a VPS with 4 GB RAM can run many thousands of processes without each process directly owning a fixed physical section of RAM.