I found this script FPMurphy posted on a thread here but i couldnt make it work for Solaris:
Code:
PORT=8103
PIDS=`ps -ef | sed 1d | awk '{print $2}'`
for pid in $PIDS
do
/usr/proc/bin/pfiles $pid 2>/dev/null | grep -q "port: $PORT"
if [[ $? -eq 0 ]] ; then
echo "Port: $PORT is being used by PID: \c"
ps -o pid -o args -p $PID | sed 1d
fi
done
Function of grep -q in Linux is not provided on solaris.. So i got this:
So i tried below part with xargs even without being sure about how exact output of "/usr/proc/bin/pfiles $pid" part seems like, im sorry a bit stuck with time...
Code:
PORT=8103
PIDS=`ps -ef | sed 1d | awk '{print $2}'`
for pid in $PIDS
do
/usr/proc/bin/pfiles $pid 2>/dev/null | xargs grep "port: $PORT"
if [[ $? -eq 0 ]] ; then
echo "Port: $PORT is being used by PID: \c"
ps -o pid -o args -p $PID | sed 1d
fi
done
I had this meaningless output:
Code:
grep: can't open 23534:
grep: can't open -bash
grep: can't open Current
grep: can't open rlimit:
grep: can't open 256
grep: can't open file
grep: can't open descriptors
grep: can't open 0:
grep: can't open S_IFCHR
grep: can't open mode:0600
grep: can't open dev:292,0
grep: can't open ino:12582922
grep: can't open uid:100
if /usr/proc/bin/pfiles $pid 2>/dev/null | grep "port: $PORT" >/dev/null
then
echo "Port: $PORT is being used by PID: \c"
ps -o pid -o args -p $PID | sed 1d
fi
PORT=8103
PIDS=`ps -ef | sed 1d | awk '{print $2}'`
for pid in $PIDS
do
if /usr/proc/bin/pfiles $pid 2>/dev/null | grep "port: $PORT" >/dev/null
then
echo "Port: $PORT is being used by PID: \c"
ps -o pid -o args -p $PIDS | sed 1d
fi
done
root@dx311 # ./port_PID_relation.sh
Code:
Port: 8103 is being used by PID: \c
usage: ps [ -aAdeflcjLPyZ ] [ -o format ] [ -t termlist ]
[ -u userlist ] [ -U userlist ] [ -G grouplist ]
[ -p proclist ] [ -g pgrplist ] [ -s sidlist ] [ -z zonelist ]
'format' is one or more of:
user ruser group rgroup uid ruid gid rgid pid ppid pgid sid taskid ctid
pri opri pcpu pmem vsz rss osz nice class time etime stime zone zoneid
f s c lwp nlwp psr tty addr wchan fname comm args projid project pset
ok now i have changed script a bit "pid" instead of $PIDS then i got the output below but still there is a problem PID: \c prints..
Code:
PORT=8103
PIDS=`ps -ef | sed 1d | awk '{print $2}'`
for pid in $PIDS
do
if /usr/proc/bin/pfiles $pid 2>/dev/null | grep "port: $PORT" >/dev/null
then
echo "Port: $PORT is being used by PID: \c"
ps -o pid -o args -p $pid | sed 1d
fi
done;
Code:
root@dx311 # ./port_PID_relation.sh
Port: 8103 is being used by PID: \c
28219 /usr/java/bin/java -server -Xms1024M -Xmx1024M -Xloggc:data/log/gc.out -Dhttp.p
Port: 8103 is being used by PID: \c
20613 grep port: 8103
Hi
The clients connect to my server -using port 9130. But no client could connect to my server at this time. I've checked already and this is the result
netstat -Aan|grep -v 127.0.0.1|grep 9130|pg
f10006000abcb398 tcp4 10313 0 10.0.89.81.9130 10.158.70.24.1705 CLOSE_WAIT... (8 Replies)
Hello Friends,
Hope you are doing well.
I just need a help in executing multiple processes.
I've written a shell script which calls another scritps. But the problem is there are too many processes to run, and each process takes about a min to finish its execution.
So, I want to just... (3 Replies)
Does anyone know if there is a C API call to get the status of a TCP port? As opposed to running netstat and parsing the results. At the moment I have to attempt to bind() and pick up on the address in use error which isn't very elegant
Thanks
---------- Post updated at 10:42 AM ----------... (0 Replies)
Hi,
I want to kill TCP connections which have status as TIME_WAIT & no PID
(as per the output of the "netstat - p" command).
Is there any command/utility available to kill connections to a specific port or IP address.
The problem is that these connections don't have process ID (see... (4 Replies)
There is a server and a client,when client send a message to server,server can send a reply to client. The status of server and client is ESTABLISHED.Then I halt the client,I find the server status is CLOSE_WAIT and the client status is FIN_WAIT_2. Many minutes passed,I find the the server status... (1 Reply)
Hi,
I have an application with a bug in it that keeps sockets in CLOSE_WAIT, which eventually freezes the server because the user account it runs under runs out of file handles. We have the bug fixed but can only release the fix with the next release.
Does anyone know how I can clear the... (3 Replies)
Hi,
I need to retrieve the exit status of 4 moves running as background processes. The wait command will not work since it can only give me the exit status of the last of the background processes.
Here's a sample of what I need
!#/bin/ksh
mv /dir1/subdir1/*.Z /dir6/subdir6/ &
mv... (2 Replies)