
For example you can list all the information about what is happening on your interfaces when you like to know things about the interface extend the lsof command with a -i and if you like to know something about a specific port you can extend the lsof command with -i :(port-number). For example you can use the following command 'lsof -i :521'. This will give you all the information about the processes running in conjunction with port 521.
However, lsof is not limited to interfaces only, you can for example list everything that is linked to a specific process id. For example I checked which process id is my current bash shell and found out that it is 184. So the command 'lsof -p 184' will show me the following:
johan-louwerss-macbook-pro:Versions jlouwers$ lsof -p 184
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
bash 184 jlouwers cwd DIR 14,2 476 166647 /System/Library/Frameworks/JavaVM.framework/Versions
bash 184 jlouwers txt REG 14,2 1244928 21392 /bin/bash
bash 184 jlouwers txt REG 14,2 1059776 21697 /usr/lib/dyld
bash 184 jlouwers txt REG 14,2 134975488 700983 /private/var/db/dyld/dyld_shared_cache_i386
bash 184 jlouwers 0u CHR 16,0 0t315770 153056004 /dev/ttys000
bash 184 jlouwers 1u CHR 16,0 0t315770 153056004 /dev/ttys000
bash 184 jlouwers 2u CHR 16,0 0t315770 153056004 /dev/ttys000
bash 184 jlouwers 255u CHR 16,0 0t315770 153056004 /dev/ttys000
johan-louwerss-macbook-pro:Versions jlouwers$
lsof is also a 'replacement' for the fuser command. You can extend the lsof command wit a +d. For example execute the command: lsof +d /var/log/messages you will get a list of all processes who are writing and keeping locks on this file.
There are a lot more options in lsof you have to explore. just do a man lsof and you will find a lot more options that you can use.
No comments:
Post a Comment