Blog dedicated to Oracle Applications (E-Business Suite) Technology; covers Apps Architecture, Administration and third party bolt-ons to Apps

Showing posts with label port. Show all posts
Showing posts with label port. Show all posts

Monday, May 18, 2009

Script to get the process which listens on a port number

In Solaris 10, lsof utility doesn't work. Here's a script given by Oracle in Metalink Note 839919.1 to help us:

#!/bin/bash

# Get the process which listens on port

# $1 is the port we are looking for

if [ $# -lt 1 ]
then
echo "Please provide a port number parameter for this script"
echo "e.g. $0 22"
exit
fi

echo "Greping for your port, please be patient (CTRL+C breaks) ... "

for i in `ls /proc`
do
[ -d /proc/$i ] && pfiles $i | grep AF_INET | grep $1
if [ $? -eq 0 ]
then
echo Is owned by pid $i
fi
done

Monday, October 20, 2008

How to check if a port is in use

This is the most common question asked by DBAs and System Admins.

The easiest way to find out is this:

telnet hostname port number

For example to check if port 22000 is in use, use this command:

telnet justanexample.com 22000

If the port is in use, the screen will go blank.  You can then press Ctrl + ] to get to telnet prompt, from where you can type exit and quit.

If the port is not in use, you'll get a message like  "Connect timed out".  This works for all operating systems supporting TCP/IP that's all unix and all windows versions.

Thursday, August 2, 2007

How to find the pid of a process which is using a specific port

The lsof unix command can give you the detail. lsof stands for list of open files. lsof command lists information about files opened by

An open file may be a regular file, a directory, a block special file, a character special file, an executing text reference, a library, a stream or a network file (Internet socket, NFS file or UNIX domain socket.) A specific file or
all the files in a file system may be selected by path.

In Solaris lsof is present in /usr/local/bin/lsof usually.

lsof | grep will return an output like this one:

lsof
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME


Good document for finding out the same information on Linux is: http://www.redhat.com/docs/manuals/linux/RHL-9-Manual/security-guide/s1-server-ports.html

For HP-UX, lsof is not part of the standard install. You can download it from:

http://ftp.cerias.purdue.edu/pub/tools/unix/sysutils/lsof/binaries/hpux/

Solaris 10 has issues with lsof version 4.77. Ensure that you are using lsof version 4.8 on Solaris 10 to get correct results.

If you don't have lsof on Solaris this My Oracle Support (erstwhile Metalink) Article has a script

When "lsof" Utility Is Not Installed, How To Determine Which Process is Using a TCP Port on Sun Solaris Platforms? [ID 839919.1]

This gives a script get_port_pid.sh:

#!/bin/bash

# Get the process which listens on port

# $1 is the port we are looking for

if [ $# -lt 1 ]
then
echo "Please provide a port number parameter for this script"
echo "e.g. $0 22"
exit
fi

echo "Greping for your port, please be patient (CTRL+C breaks) ... "

for i in `ls /proc`
do
[ -d /proc/$i ] && pfiles $i | grep AF_INET | grep $1
if [ $? -eq 0 ]
then
echo Is owned by pid $i
fi
done