When managing services on a Linux server, one practical difference becomes clear:
For Nginx, killing the master process is usually enough.
For Gunicorn, we often kill all processes.
Here’s the difference — clearly and point-to-point.
1️⃣ Process Model
Nginx
Uses master–worker model.
Master tightly controls workers.
Workers cannot operate independently.
If master dies, workers exit automatically.
Gunicorn
Also uses master–worker (prefork model).
Workers are less tightly bound.
If master is force killed (
kill -9), workers may survive.Manual cleanup may be required.
2️⃣ Shutdown Behavior
Nginx
Handles graceful shutdown well.
Master sends signals to workers.
Clean exit happens automatically.
Rarely leaves leftover processes.
Gunicorn
If killed forcefully, cleanup logic does not run.
Workers may keep running.
Port may remain occupied.
Restart can fail with “Address already in use”.
3️⃣ Port Handling
Nginx
Master controls socket binding.
Killing master usually frees port.
Workers shut down with it.
Gunicorn
Workers bind to the application port (e.g., 8000).
If even one worker survives, port remains busy.
New instance cannot start properly.
4️⃣ Service Management
Nginx
Usually managed by systemd.
Process tree is tracked.
Clean lifecycle control.
Gunicorn
Often started manually in development.
Not always managed by systemd.
Manual killing may be needed.
5️⃣ What We Do in Practice
For Nginx
kill <master_pid>
or
systemctl stop nginx
For Gunicorn
pkill gunicorn
or
kill -9 \((ps -ef | grep gunicorn | awk '{print \)2}' | head -n 2)
Ensures:
All workers stopped
Port released
Clean restart
6️⃣ Is This About Zombie Processes?
No.
This is about:
Worker cleanup
Signal handling
Port release
Process tree control