Thursday, March 13, 2008

Identifying the process that is listening on a port

There are several times when we try to bring up a process and we get a port conflict. But if you ever wondered which process is running on that port, it is easy to find out.
In most unix systems you can use the lsof command which is normally available under /usr/local/bin/lsof. The only catch is you have to be root or have sudo access to run this command.

lsof -i TCP: will list the process that is listening on . So if you are trying to find out the process id that is listening on port 80, issue the command "lsof -i TCP:80". For more information on the lsof command refer to the manual.

Once you find the process id, you can get more information about the process by using the ps command.

There is a developer works article that has good usage information about lsof.

If your system does not have the lsof command due to security restrictions, you may want to try the script found here.

1 comment:

jean said...

You can also find out about the process id by running the netstat command with -p option.

For example the following command will list all the process that are listening for connections from other clients.

netstat -lp

If the process is not owned by the user who is running the command, the process information will not be displayed, unless you are running the command as a super user.