Process & Resource Management
Debug running Rust services with ps, htop, signals, and perf. Validate graceful shutdown, thread counts, and memory growth under load.
Busca en todas las páginas de la documentación
Debug running Rust services with ps, htop, signals, and perf. Validate graceful shutdown, thread counts, and memory growth under load.
pgrep -a my-service
kill -TERM "$(pgrep my-service)"
sleep 2
pgrep my-service || echo "exited cleanly"
htop -p "$(pgrep -d',' my-service)"When to reach for this:
# Watch open files for connection leak
PID=$(pgrep my-service)
ls -l /proc/$PID/fd | wc -l
# Sample stack with perf (Linux)
sudo perf record -g -p $PID -- sleep 30
sudo perf report
# Memory map summary
pmap -x $PID | tail -1// Ensure SIGTERM handled in service
use tokio::signal;
async fn shutdown_signal() {
signal::ctrl_c().await.ok();
signal::unix::signal(signal::unix::SignalKind::terminate())
.unwrap()
.recv()
.await
.ok();
}What this demonstrates:
/proc/$PID/fd counts open sockets/filesperf attributes CPU to symbols (with debug symbols)| Signal | Use |
|---|---|
| SIGTERM (15) | Graceful shutdown request |
| SIGINT (2) | Ctrl-C local dev |
| SIGKILL (9) | Force kill, no cleanup |
| SIGHUP (1) | Reload config (if implemented) |
Default multi-thread runtime uses ~N worker threads; blocking pool adds more under spawn_blocking load.
perf_event_paranoid. Fix: sysctl adjust or sudo.systemctl status for current PID.| Alternative | Use When | Don't Use When |
|---|---|---|
tokio-console | Async task introspection | Production always-on |
heaptrack / dhat | Allocator profiling | Quick CPU check |
bpftrace | Kernel-level tracing | Simple local dev |
Tokio worker threads plus a few blocking threads; investigate hundreds.
Use samply or Instruments instead of Linux perf.
Set ulimits in compose or K8s security context for connection-heavy Axum services.
Stack versions: This page was written for Rust 1.97.0 (edition 2024), Tokio 1.x, Axum 0.8, serde 1.0, sqlx 0.8, clap 4, and Polars 0.46+.
Revisado por Chris St. John·Última actualización: 16 jul 2026