Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lsof #51

Open
nonocast opened this issue Nov 8, 2019 · 0 comments
Open

lsof #51

nonocast opened this issue Nov 8, 2019 · 0 comments

Comments

@nonocast
Copy link
Owner

nonocast commented Nov 8, 2019

lsof - list open files

在linux下everything is file, 所以lsof是利器。

  • 查看端口占用情况
    通过nc -l 9999打开端口,然后用lsof -i :9999查看占用情况
lsof -i :9999
COMMAND   PID     USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
nc      19856 nonocast    3u  IPv4 0x59c33e997832cee1      0t0  TCP *:distinct (LISTEN)
  • 查看文件占用情况
    通过touch foo创建文件, 然后tail -f foo占用掉这个文件, 最后lsof foo查看占用情况
$ lsof foo
COMMAND   PID     USER   FD   TYPE DEVICE SIZE/OFF     NODE NAME
tail    19728 nonocast    3r   REG    1,4       12 64987891 foo
  • 查看进程占用情况
 lsof -p 3137 
COMMAND   PID     USER   FD      TYPE             DEVICE   SIZE/OFF                NODE NAME
Evernote 3137 nonocast  cwd       DIR                1,4        320            53481396 /Users/nonocast/Library/Containers/com.evernote.Evernote/Data
Evernote 3137 nonocast  txt       REG                1,4   13160208            10194243 /Applications/Evernote.app/Contents/MacOS/Evernote
Evernote 3137 nonocast  txt       REG                1,4      75696             3958353 /Applications/Evernote.app/Contents/Frameworks/wav2gsm.framework/Versions/A/wav2gsm
Evernote 3137 nonocast  txt       REG                1,4     436576             3958322 /Applications/Evernote.app/Contents/Frameworks/HockeySDK.framework/Versions/A/HockeySDK
Evernote 3137 nonocast  txt       REG                1,4     435008             6139516 /Applications/Evernote.app/Contents/Frameworks/CocoaLumberjack.framework/Versions/A/CocoaLumberjack
Evernote 3137 nonocast  txt       REG                1,4      42304            10194134 /Applications/Evernote.app/Contents/Frameworks/ENLogging.framework/Versions/A/ENLogging
Evernote 3137 nonocast  txt       REG                1,4     221152             3958337 /Applications/Evernote.app/Contents/Frameworks/OpenIDAppAuth.framework/Versions/A/OpenIDAppAuth
Evernote 3137 nonocast  txt       REG                1,4    6265584            10194076 /Applications/Evernote.app/Contents/Frameworks/CoreNote.framework/Versions/A/CoreNote
Evernote 3137 nonocast  txt       REG                1,4      86528            10194065 /Applications/Evernote.app/Contents/Frameworks/CommEngine.framework/Versions/A/CommEngine

参考:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant