aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/process/lsof.md
diff options
context:
space:
mode:
authorJohannes Stoelp <johannes.stoelp@gmail.com>2024-08-27 23:05:39 +0200
committerJohannes Stoelp <johannes.stoelp@gmail.com>2024-08-27 23:05:39 +0200
commite830fa716bedecbff8c3a572d1d20061342ec4c7 (patch)
tree03539ff9da6e494a2f652cbcd48d69d635ff8ca5 /src/process/lsof.md
parentf5178ed1e419cfae7679ae8b4d3130ef48abfbfd (diff)
downloadnotes-e830fa716bedecbff8c3a572d1d20061342ec4c7.tar.gz
notes-e830fa716bedecbff8c3a572d1d20061342ec4c7.zip
mv monitor -> process
Diffstat (limited to 'src/process/lsof.md')
-rw-r--r--src/process/lsof.md74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/process/lsof.md b/src/process/lsof.md
new file mode 100644
index 0000000..562c8fc
--- /dev/null
+++ b/src/process/lsof.md
@@ -0,0 +1,74 @@
+# lsof(8)
+
+```markdown
+lsof
+ -r <s> ..... repeatedly execute command ervery <s> seconds
+ -a ......... AND slection filters instead ORing (OR: default)
+ -p <pid> ... filter by <pid>
+ +fg ........ show file flags for file descripros
+ -n ......... don't convert network addr to hostnames
+ -P ......... don't convert network port to service names
+ -i <@h[:p]>. show connections to h (hostname|ip addr) with optional port p
+ -s <p:s> ... in conjunction with '-i' filter for protocol <p> in state <s>
+ -U ......... show unix domain sockets ('@' indicates abstract sock name, see unix(7))
+```
+
+```markdown
+file flags:
+ R/W/RW ..... read/write/read-write
+ CR ......... create
+ AP ......... append
+ TR ......... truncate
+```
+
+```markdown
+-s protocols
+ TCP, UDP
+
+-s states (TCP)
+ CLOSED, IDLE, BOUND, LISTEN, ESTABLISHED, SYN_SENT, SYN_RCDV, ESTABLISHED,
+ CLOSE_WAIT, FIN_WAIT1, CLOSING, LAST_ACK, FIN_WAIT_2, TIME_WAIT
+
+-s states (UDP)
+ Unbound, Idle
+```
+
+# Examples
+
+## File flags
+Show open files with file flags for process:
+```markdown
+lsof +fg -p <pid>
+```
+
+## Open TCP connections
+Show open tcp connections for `$USER`:
+```markdown
+lsof -a -u $USER -i TCP
+```
+**Note**: `-a` _ands_ the results. If `-a` is not given all open files matching
+`$USER` and all tcp connections are listed (_ored_).
+
+## Open connection to specific host
+Show open connections to `localhost` for `$USER`:
+```markdown
+lsof -a -u $USER -i @localhost
+```
+
+## Open connection to specific port
+Show open connections to port `:1234` for `$USER`:
+```markdown
+lsof -a -u $USER -i :1234
+```
+
+## IPv4 TCP connections in `ESTABLISHED` state
+```markdown
+lsof -i 4TCP -s TCP:ESTABLISHED
+```
+## List open files in a mounted directory.
+This may help to find which processes keep devices busy when trying to unmount
+and the device is currently busy.
+```markdown
+# Assuming /proc is a mount point.
+lsof /proc
+```