Skip to content

Instantly share code, notes, and snippets.

@budiantoip
Last active May 9, 2025 07:29
Show Gist options
  • Save budiantoip/f11fbff03cd41ccc9db774fee6e8411b to your computer and use it in GitHub Desktop.
Save budiantoip/f11fbff03cd41ccc9db774fee6e8411b to your computer and use it in GitHub Desktop.
Debug Linux Process

Show a list of all running nginx processes, along with their PIDs and full command lines

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.

List the PIDs of all processes with the command name nginx, sorted by start time (oldest first).

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).


Show all nginx processes that are running under the www-data user.

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.


Retrieve the oldest (first started) process ID of any process named nginx

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).

Search for and return the PID of the nginx master process

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).

Print the resource limits (like max open files) for the nginx master process

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment