procfd
Introduction
procfd is a Linux tool to query open file descriptors for processes. It is a rust replacement for the lsof command. Compared to lsof, procfd features:
- Safe against blocking operations
- Easy to use command-line options
- Simple to use filters
- Very fast
- Can export data as json
Examples
Filter by PID
| | | | |
| | | | |
| | | | |
| | | | |
| | | | | )
| | | | | )
| | | | |
| | | | | )
| | | | | )
| | | | |
| | | | |
| | | | |
| | | | |
| | | | | )
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
Filtering examples
procfd --type {socket,cwd,root,exe,path,pipe}- Filter by socket typeprocfd --socket-domain {unix,inet,inet4,inet6,other}- Filter sockets by domainprocfd --socket-type {tcp,udp,unix-stream,unix-dgram}- Filter by socket typeprocfd --socket-state {listen,established,close}- Filter by socket stateprocfd --src-host 10.77.10.3 --src-port 1044 --dst-host google.com --dst-port 443- Filter by source AND destination host/portprocfd --port 443- Filter by source OR destination portprocfd --cmd ssh- Filter by command (exact match)procfd --cmd /ssh/- Filter by command (regex match)procfd --user maverick- Filter by usernameprocfd --pid 3964924- Filter by process ID
Other options
procfd --no-dns- Disable DNS lookupsprocfd --json- Render results as JSON
Comparison to lsof and lsfd
lsofis the original cross-platform command to list open file handleslsfdis a Linux-only rewrite oflsofby one of the main contributors tolsofwhich addresses many usability issues withlsof
Below is an incomplete comparison of these tools:
| Feature | procfd | lsof | lsfd |
|---|---|---|---|
| Language | rust | C | C |
| Platform support | Linux only | Cross-platform | Linux only |
| Speed | Very fast | Variable [^1] | Variable |
| JSON output | Yes | No | Yes |
| Avoid blocking operations | Yes | Partial [^2] | No |
| Display endpoint of unix sockets | Yes | Very slow with -E flag | No |
| Display endpoint of pipes | Yes | Very slow with -E flag | Yes |
| Usability | Very easy | Complicated | Medium |
| Show memory maps | No[^3] | Yes | Yes |
| Filter by expression | No | No | Yes |
| DNS Lookups | Yes | Yes | No |
| Show mount points | No | Yes | Yes |
| IPv6 support | Yes | Yes | Yes |
| Filter by path | No[^4] | Yes | Yes |
| Filter by command | Yes with regex | Yes exact match | Yes with regex |
| Filter by src/dst host/port | Yes | No | Yes |
Notes
[^1]: Fast with local disks, but can be slow with lots of mounted network filesystems
[^2]: lsof -b flag avoids blocking calls, but also fails to display any socket information
[^3]: Not currently implemented but PRs welcome!
[^4]: Not currently implemented, but can use grep to filter output of procfd --type path
History
procfd was contributed back to the community by the D. E. Shaw group.
License
This project is released under a BSD-3-Clause license.
We love contributions! Before you can contribute, please sign and submit this Contributor License Agreement (CLA). This CLA is in place to protect all users of this project.