Sunday, April 19, 2009

lsof can be used in many ways for troubleshooting purposes

lsof is a very useful command. Is shows various opened files. You may use lsof with specific port,pid or process.When used in correct context,it will save your life in difficult troubleshooting sessions.

Suppose you want to see what are the various services running in you server. I know you will say netstat. But you may also use lsof -i -n.

lsof -i -n

-n for overriding dns resolution
Lets discuss some of other cases too.
lsof -i:389

Port 389 is used by ldap by default.
This will show all the services on this port. It will also show connection status too.
lsof -i:143 -n

-n will give ip address instead of fqdn
lsof -p:1234

There were some situation when some stale processes were hindering new processes to spawn. This switch will display all the files,connections,sockets opened by it.
We can confirm if the particular process is stale(before kill -9)
-c process_name
lsof -c dhcpd

This switch will show all the files(connection status,type) and many other regular info of this process.

No comments: