← CodeClarityLab Home
Browse by Category
+ added · updated 7d
← Back to glossary

Linux Processes

linux PHP 5.0+ Intermediate

Also Known As

PID process management signals kill command

TL;DR

Every running program is a process with a PID, memory space, and file descriptors — ps, top, kill, and signals are the essential tools for managing them.

Explanation

Each process has a PID (process ID), parent PID (PPID), memory map, open file descriptors, and a signal mask. Key tools: ps aux (snapshot of all processes), top/htop (live view), kill -SIGNAL PID (send signal), strace (trace system calls), lsof (open files per process). Signals: SIGTERM (graceful shutdown request), SIGKILL (immediate termination, cannot be caught), SIGHUP (reload config), SIGUSR1/SIGUSR2 (custom). PHP-FPM responds to SIGTERM for graceful shutdown and SIGUSR2 for reload.

Common Misconception

kill kills a process immediately — kill sends SIGTERM by default, which asks the process to shut down gracefully; only kill -9 (SIGKILL) forces immediate termination.

Why It Matters

Understanding signals is essential for zero-downtime PHP-FPM reloads, graceful queue worker shutdown, and diagnosing hung processes — kill -9 should always be the last resort.

Common Mistakes

  • Using kill -9 as the first option — SIGKILL prevents cleanup, open file handles stay open, transactions may be left incomplete.
  • Not handling SIGTERM in queue workers — workers killed mid-job corrupt the queue state.
  • ps aux grep includes the grep process itself in results — use ps aux | grep [p]rocess to exclude it.
  • Not knowing that zombie processes are already dead — they are waiting for the parent to read their exit code; kill the parent or fix the parent to wait().

Code Examples

✗ Vulnerable
# Brutal kill — no cleanup, potential data loss:
kill -9 $(pgrep php-fpm)   # Immediately kills all FPM workers
# Active requests terminated mid-execution
# DB transactions left open
# Temp files not cleaned up
✓ Fixed
# Graceful PHP-FPM reload (zero-downtime):
kill -USR2 $(cat /var/run/php-fpm.pid)  # Reload config, finish active requests

# Graceful shutdown (waits for active requests):
kill -TERM $(cat /var/run/php-fpm.pid)  # SIGTERM — graceful

# Monitor:
watch -n1 'ps aux | grep php-fpm | grep -v grep'

# Queue worker: handle SIGTERM gracefully in PHP:
pcntl_async_signals(true);
pcntl_signal(SIGTERM, function() use (&$running) { $running = false; });

Added 15 Mar 2026
Edited 22 Mar 2026
Views 76
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 2 pings S 0 pings M 0 pings T 3 pings W 2 pings T 2 pings F 2 pings S 3 pings S 1 ping M 0 pings T 1 ping W 0 pings T
No pings yet today
ChatGPT 30 Amazonbot 13 Perplexity 12 Google 6 Unknown AI 3 Ahrefs 3 SEMrush 2 Majestic 1 Qwen 1
crawler 66 crawler_json 3 pre-tracking 2
DEV INTEL Tools & Severity
🟡 Medium ⚙ Fix effort: Low
⚡ Quick Fix
Use ps aux, top, or htop to identify runaway PHP processes; set memory_limit and max_execution_time in php.ini to prevent resource exhaustion
📦 Applies To
PHP 5.0+ web cli
🔗 Prerequisites
🔍 Detection Hints
PHP process consuming 100% CPU or memory; zombie processes; PHP-FPM workers not being reaped
Auto-detectable: ✓ Yes htop ps strace perf
⚠ Related Problems
🤖 AI Agent
Confidence: Medium False Positives: Medium ✗ Manual fix Fix: Medium Context: File

✓ schema.org compliant