1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-05 16:18:01 +00:00

Add Check If A Port Is In Use as a zsh til.

This commit is contained in:
jbranchaud
2015-06-11 19:55:35 -05:00
parent f55552bda2
commit fdd02b2253
2 changed files with 19 additions and 0 deletions

View File

@@ -142,6 +142,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
- [All The Environment Variables](zsh/all-the-environment-variables.md) - [All The Environment Variables](zsh/all-the-environment-variables.md)
- [Cat A File With Line Numbers](zsh/cat-a-file-with-line-numbers.md) - [Cat A File With Line Numbers](zsh/cat-a-file-with-line-numbers.md)
- [Check If A Port Is In Use](zsh/check-if-a-port-is-in-use.md)
- [Clear The Screen](zsh/clear-the-screen.md) - [Clear The Screen](zsh/clear-the-screen.md)
- [Create A File Descriptor with Process Substitution](zsh/create-a-file-descriptor-with-process-substitution.md) - [Create A File Descriptor with Process Substitution](zsh/create-a-file-descriptor-with-process-substitution.md)
- [Killing A Frozen SSH Session](zsh/killing-a-frozen-ssh-session.md) - [Killing A Frozen SSH Session](zsh/killing-a-frozen-ssh-session.md)

View File

@@ -0,0 +1,18 @@
# Check If A Port Is In Use
The `lsof` command is used to *list open files*. This includes listing
network connections. This means I can check if a particular port is in use
and what process is using that port. For instance, I can check if my rails
application is currently running on port 3000.
```
$ lsof -i TCP:3000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
ruby 13821 jbranchaud 12u IPv6 0xdf2e9fd346cc12b5 0t0 TCP localhost:hbci (LISTEN)
ruby 13821 jbranchaud 13u IPv4 0xdf2e9fd33ca74d65 0t0 TCP localhost:hbci (LISTEN)
```
I can see that a ruby process (my rails app) is using port 3000. The PID
and a number of other details are included.
See more details with `man lsof`.