Linux /proc and Process Debugging

Low-level Linux process inspection with /proc, syscall tracing, profilers, debuggers, and core dumps.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## /proc Process Filesystem
Read process command line
tr "\0" " " < /proc/1234/cmdline; echo

# Print the null-separated command line from /proc.

Read process environment
tr "\0" "
" < /proc/1234/environ | head

# Inspect environment variables of a process when permitted.

List open descriptors via /proc
ls -l /proc/1234/fd | head

# Inspect file descriptors directly from procfs.

Show resource limits
cat /proc/1234/limits

# Display RLIMIT values for a process.

Show memory map via /proc
head -40 /proc/1234/maps

# Inspect mapped memory regions and permissions.

Show detailed memory map
head -80 /proc/1234/smaps

# Inspect detailed per-region memory accounting.

Show kernel stack for PID
sudo cat /proc/1234/stack

# Inspect a sleeping task kernel stack when permitted.

Show scheduler details
cat /proc/1234/sched | head -40

# Inspect scheduling statistics and vruntime data.

## Tracing System Calls and Libraries
Trace a command with strace
strace -o trace.log ./program

# Trace syscalls made by a new command.

Attach strace to a running PID
sudo strace -p 1234

# Attach to a live process and trace syscalls.

Trace child processes too
strace -ff -o trace ./server

# Write one trace file per process and follow forks.

Trace network syscalls
strace -e trace=network -p 1234

# Focus on network-related system calls only.

Trace file syscalls
strace -e trace=file -p 1234

# Focus on file and pathname operations.

Trace library calls
ltrace -o ltrace.log ./program

# Trace dynamic library calls if ltrace is installed.

Profile hot code paths
sudo perf top

# Sample hot functions on the system in real time.

Record perf samples for PID
sudo perf record -p 1234 -- sleep 30

# Collect CPU samples for one PID over time.

Inspect recorded samples
sudo perf report

# Analyze a perf recording interactively.

## Debuggers and Core Dumps
Attach gdb to PID
gdb -p 1234

# Attach a debugger to a running process.

Batch backtrace with gdb
gdb -batch -ex "thread apply all bt" -p 1234

# Collect all-thread backtraces from a live process.

List captured core dumps
coredumpctl list

# List core dumps managed by systemd-coredump.

Open latest core in gdb
coredumpctl gdb 1234

# Load the newest core dump for a PID into gdb.

Enable core dumps in shell
ulimit -c unlimited

# Allow the shell to generate core dumps.

Recommended next

No recommendations yet.