Wednesday, November 12, 2008

UNIX lsof

Operating Oracle Application servers under Linux and UNIX requires from time to time that you find out why the application is having performance problems. When starting to debug the application server one of the first things you most likely will be doing is mine the logfiles, check all kind of Oracle tools and at some point you will have to start looking at the operating system. When looking at the operating system one of your best friends will be lsof. lsof stands for LiSt Of Files and lists information about files opened by processes for the following UNIX dialects. As everything under Linux is a file this tool will show you everything you could possible want to know.

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.





Post a Comment