ps -C nginx -o pid,cmd
ps -C nginx
: select processes with the command name nginx.-o pid,cmd
: show only the PID and COMMAND columns.
ps -C nginx -o pid= --sort=+start_time
-
-C nginx
: selects all processes named exactly nginx. -
-o pid=
: outputs only the PID (no headers). -
--sort=+start_time
: sorts processes from oldest to newest.
Useful for: grabbing the master Nginx PID (it's the oldest one).
ps -u www-data -C nginx
-u www-data
: restrict to processes owned by the www-data user.-C nginx
: match the command name nginx.
Useful for: confirming that worker processes (which run as www-data) are alive.
pgrep -xo nginx
pgrep
: searches for processes by name.-x
: matches the exact name (nginx, not nginx-something).-o
: returns the oldest PID (usually the master process in Nginx).
pgrep -f 'nginx: master process'
pgrep -f
: matches the full command line of each process.'nginx: master process'
: string found in the command name of the master process. Useful for: getting the correct master PID to inspect limits or send signals (e.g., reload).
cat /proc/$(pgrep -xo nginx)/limits
/proc/<PID>/limits
: is a virtual file showing what the kernel limits are for that specific process.$(pgrep -xo nginx)
: injects the master PID dynamically.