How to view open connections on files
During a pairing session on Ruby, we had an issue with what file the API was stuck on. Luckily, there is a command lsof
which stands for list open files.
Usage
When lsof
is ran without parameters, it will show all the files opened by any process. It can get a bit messy, so I recommend grep
ing through to find the file/process you want.
To find out what files Ruby has opened you can use lsof -c
. Here is what it looks like when running rails server
:
To find out what is accessing any file in a directory, use the lsof +D /usr/directory
You can list all opened internet sockets using lsof -i
.
After finding the process id, you can find out what that process is accessing using lsof +p PID
Using several commands leads you to any files that may be stuck in processing. I have found that it is an essential tool in debugging a multitude of issues.
References
No comments yet. Share on Mastodon and see your comment or write a post on your blog if you support Webmentions
No reposts yet. Share on Mastodon and see your repost or write a post on your blog if you support Webmentions
No likes yet. Share on Mastodon and see your like or write a post on your blog if you support Webmentions
No bookmarks yet. Share on Mastodon and see your bookmark or write a post on your blog if you support Webmentions
Powered by Webmentions