Lately I wasn’t able to startup an application cause the port needed was already used by another process.
An istance of the process I was attempting to run resulted to be idle, but it wasn’t really straight forward to identify that process by executing the command
ps -ef | grep ...
I have found useful a script that I have found in internet and that I have used in the following way.
1. First of all, create a shell script file
vi which_pid_is_bounded_to_port.sh
2. Then type in the following script and save
#!/bin/ksh line='---------------------------------------------' pids=$(/usr/bin/ps -ef -o pid=) if [ $# -eq 0 ]; then read ans?"Enter port you would like to know pid for: " else ans=$1 fi for f in $pids do /usr/proc/bin/pfiles $f 2>/dev/null | /usr/xpg4/bin/grep -q "port: $ans" if [ $? -eq 0 ]; then echo $line echo "Port: $ans is being used by PID:\c" pargs -l $f #/usr/bin/ps -o pid,args -p $f fi done
3. Now you can run the script and prompt the port in order to find the pid is bound to
. ./which_pid_is_bounded_to_port.sh Enter port you would like to know pid for: 8080
4. You will get an output that looks like the following:
--------------------------------------------- Port: 8080 is being used by PID:/usr/server/http
5. If you haven’t got the PID in the previous step, you can obtain it with the following:
ps -ef | grep /usr/server/http user 585 15735 0 16:49:43 pts/12 0:00 grep /usr/server/http user 17018 13104 0 15:57:44 pts/12 0:25 /usr/server/http
Once you get the PID, you can kill the process if you need it.
kill -9 17018








