Process monitoring

On this page 7

Process monitoring is the continuous observation of running programs on a host to confirm that each required process is alive, healthy and within its resource budget, and to alert or act when it is not. In the field of services & processes on servers, it covers daemons, worker processes and long-running jobs, from a single web server to hundreds of containerized workers.

Effective process monitoring answers three questions at all times: is the process running, is it doing useful work, and is it consuming a reasonable share of CPU, memory and file descriptors. Tools range from process supervisors such as Supervisord, PM2, Monit and systemd to full observability platforms that collect metrics, logs and traces.

How process monitoring observes a running process

Process monitoring works by sampling the state of each process at regular intervals or by receiving events from the operating system. On Linux the raw data comes from the /proc filesystem, which exposes the process ID, state, CPU ticks, resident memory, open file descriptors and thread count for every process.

Monitoring agents identify the target process in one of several ways: by a PID file written at startup, by matching the command line, by cgroup membership under systemd, or by being the direct parent process. The parent approach is the most reliable, because a supervisor that started the child receives the SIGCHLD signal the instant it exits and cannot be fooled by a stale PID file pointing to a recycled process ID.

The table below compares the main detection methods and their trade-offs.

MethodHow it worksMain weakness
Parent supervisionSupervisor forks the process and waits on itWorks only for processes it started
PID file checkReads a stored PID and tests if it existsStale files and PID reuse cause false results
Command-line matchingSearches the process table by name or argumentsSimilar processes may match by mistake
Cgroup trackingCounts all processes in a control groupRequires systemd or a container runtime
Health endpoint pollingRequests a status URL or socketAdds network load and needs application support
Ways to detect and track a monitored process

Liveness, readiness and resource health

A process that exists is not necessarily working. Mature process monitoring therefore distinguishes several layers of health, each answering a different question and triggering a different response.

LayerQuestion answeredTypical signalUsual response
ExistenceIs the process runningPID present, state not zombieRestart the process
LivenessIs it responsiveHeartbeat, watchdog ping, health checkKill and restart
ReadinessCan it accept trafficReadiness endpoint, port bindingRemove from load balancer
Resource healthIs usage within limitsCPU, memory, file descriptorsAlert or graceful restart
Functional healthIs it producing correct outputQueue depth, error rate, latencyAlert an operator
Health layers in process monitoring

The distinction matters because a hung process passes the existence test while serving nothing. Liveness checks catch deadlocks and infinite loops, while resource checks catch slow memory leaks and descriptor exhaustion before they crash the service or the whole server.

Process supervisors and monitoring tools compared

Process monitoring is implemented either by a supervisor that owns the process or by an external monitor that observes it. Many production setups combine both: a supervisor keeps the process alive, while a metrics system records trends and notifies people.

ToolModelTypical use
systemdInit system and supervisorNative Linux services with restart policies
SupervisordUser-space supervisorSeveral application workers on one host
PM2Supervisor for Node.jsJavaScript applications and clusters
MonitExternal checker with actionsResource thresholds and simple restarts
Prometheus exportersMetrics collectionTrends, dashboards and alert rules
Kubernetes probesOrchestrator health checksContainers with liveness and readiness probes
Common process monitoring tools

Supervisors apply a service restart policy, such as restarting always, only on failure, or never, often with a backoff delay. Without backoff, a process that fails immediately at startup can enter a crash loop, consuming CPU and flooding logs while never becoming healthy.

Designing alerts and automatic actions

Good process monitoring automates the routine recovery and escalates to humans only when automation cannot help. The thresholds and actions should reflect the cost of a false alarm versus the cost of a missed failure.

ConditionThresholdAction
Worker process exitsAny unexpected exitRestart with exponential backoff
Restarts in a short windowMore than 5 in 10 minutesStop restarting and page on-call
Resident memoryAbove 90% of the limit for 5 minutesGraceful restart and warning
Open file descriptorsAbove 80% of the ulimitAlert with process details
Heartbeat missingNo signal for 3 intervalsKill and restart the process
Example monitoring rules for a web application server

Thresholds should use sustained conditions rather than single samples, because short spikes in CPU or memory are normal. Alerts should carry the process name, host, PID and recent log lines, so that the responder can act without logging in to gather context.

Common pitfalls in process monitoring

Most failures of process monitoring come from checking too little or acting too aggressively. The following mistakes appear frequently in production environments.

  • Monitoring only existence: a deadlocked worker keeps its PID and silently stops serving requests.
  • Relying on stale PID files: after a crash, the stored PID may belong to an unrelated process.
  • Restarting without limits: unbounded restarts hide configuration errors and create crash loops.
  • Double supervision: two supervisors managing the same process fight each other and cause duplicate instances.
  • Monitoring from the same host only: if the host fails, the monitor fails with it, so an external check is still needed.

A further risk is alert fatigue. When every brief restart sends a notification, operators learn to ignore alerts, and a genuine outage goes unnoticed. Grouping related events and alerting on user-facing symptoms keeps the signal useful.

Understanding it simply

A server runs many programs in the background, much like a building runs elevators, heating and lights. Process monitoring is the caretaker who walks the building, checking that each system is switched on, actually working and not overheating.

When something stops, the caretaker restarts it right away. When something keeps breaking, the caretaker calls a specialist instead of restarting it forever. The key idea is that problems are noticed and handled before visitors notice them.

Applied in practice

A small software company runs its customer portal on two Linux servers. Each server hosts a Node.js application managed by PM2 with four worker processes, plus a background queue worker supervised by systemd with a restart-on-failure policy and a 5-second backoff.

One evening a new release introduces a memory leak in the queue worker. Resident memory grows by roughly 50 MB per hour. Monit detects memory above 90% of the configured limit for five minutes, performs a graceful restart and sends a warning that includes the process name and recent logs.

The restarts keep the queue running overnight, and the alert history shows a clear pattern. The next morning engineers trace the leak to an unclosed database cursor, ship a fix and avoid any customer-facing outage.