Wednesday, September 5, 2007

Soalris: Kill a process which is using a particular port number

Today i came across a problem in solaris. The problem was that while starting my application server, it was throwing an error "Address already in use".

My app server is a java process and there are many other java process which are running on my zone. But the issue is, how may i know that which java process is using that particular port?

I followed following steps:
1. List all the java process running on my zone ( ps -eaf |grep vagrawal| grep java )
2. Go through each java process and check if it using that particular port ( pfiles $pid|grep 1182 )
(here $pid is the process id of the java process and 1182 is the port number of which i am looking for)


Above method works fine but it is bit a long process, as i have to run step 2 for all java processes, so i ran a folowing command on my console:

for i in `ps -e|awk '{print $1}'`; do echo $i; pfiles $i 2>/dev/null | grep 'port: 1188'; done

Above command/script will list out all the process ID and will tell if any process is using port 1188

Now i have process ID of the process which is occupying my port, and i can kill that by kill -9 pid

No comments: