brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: lsof -p shows every file and socket one process has open

Troubleshooting
~/tips/tip-troubleshooting-lsof-p-process

sudo lsof -nP -p 1234

See which config, log and network connections a running program is using.

Which config file did that service really load, and where is it logging to? A running process can answer both, because the files it holds open are listed per process ID.

sudo lsof -nP -p 1234

-n and -P keep addresses and ports as numbers, which is faster and less confusing. The FD column tells you the role of each line: cwd is the working directory, txt is program code, and a number followed by r, w or u is an open file for reading, writing or both.

I scan the w entries to find the log file nobody documented. To narrow the list to network sockets only, combine two filters:

sudo lsof -nP -a -p 1234 -i

The -a matters. Without it, lsof adds the two selections together and you get all open files of that process plus every network socket on the machine.

This is a snapshot. A program that reads its config at startup and closes it again won’t show that file, so an empty result there proves nothing. Without root you mostly see only your own processes. It’s often not installed on small server images, and the command prints nothing and exits with 1 when no line matches.

Further reading: lsof man page

More Troubleshooting tips Get-NetTCPConnection -State Listen modinfo -p usb_storage ps -o pid,lstart,etime,cmd -p 1234 fc-match Helvetica wp plugin list --status=active --field=name > active-plugins.txt All Troubleshooting tips (21) All topics

Link