Archive · Linux

Debugging with strace, lsof and tcpdump

Three tools that show what a misbehaving process is actually doing.

1 min read

  • Ubuntu 18.04.4 LTS
  • strace 4.21
  • lsof 4.89
  • tcpdump 4.9

When logs say nothing, look at the process directly.

# which files does it open, and where does it fail?
sudo strace -f -e trace=file -p 1234

# who has this port or file open?
sudo lsof -i :8080
sudo lsof +L1                    # deleted files still held open (a classic disk-full cause)

# is the traffic arriving?
sudo tcpdump -i eth0 -nn port 443 -c 20
Tool Answers
strace What system calls the process makes, and which return errors such as ENOENT or EACCES
lsof Which process holds which file, socket or port
tcpdump Whether packets reach the host at all

df shows a full disk but du cannot find the files? lsof +L1 often finds a deleted log still held by a running process; restarting that process frees the space. Use strace sparingly on busy production processes, because it slows them down.