Sponsored Content
Top Forums Shell Programming and Scripting Get opened port with given PID? Post 302540501 by linuxadmin on Thursday 21st of July 2011 12:58:45 AM
Old 07-21-2011
Quote:
Originally Posted by shamrock
You should be able to grep the port tomcat is listening on from the output of lsof
Dear shamrock, i tried as you told
Code:
[root@linux ~]# lsof | grep 8080
automount  2867      root  mem       REG       8,11      98080    1006186 /usr/lib/autofs/lookup_file.so

And zaxxon, what you told is correct only. I can get it from server.xml file.
But my problem is : we have to use this script in a number of servers. And the server.xml file may be manually edited. There will be http & https connections also. The part <Connector port="portNum" will edit manually. And there is a chance to change the alignment also.
Code:
[root@linux ~]# grep 8080 /tomcat6/apache-tomcat-6.0.18/conf/server.xml
         Define a non-SSL HTTP/1.1 Connector on port 8080
    <Connector port="8080" protocol="HTTP/1.1" 
               port="8080" protocol="HTTP/1.1"

So upto my knowledge , there is only one way , that to GET the PORT number from PROCESS id.
Code:
[root@linux ~]# ps -ef | grep tomcat
root      7976     1  0 Jul18 ?        00:22:11 /usr/java/jdk1.6.0_13/bin/java -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=/tomcat6/apache-tomcat-6.0.18/conf/logging.properties -verbose:gc -XX:+PrintGCDetails -XX:MaxPermSize=512M -Xms1024M -Xmx1024M -Djava.awt.headless=true -XX:+UseParallelOldGC -XX:+UseParallelGC -Djava.endorsed.dirs=/tomcat6/apache-tomcat-6.0.18/endorsed -classpath :/tomcat6/apache-tomcat-6.0.18/bin/bootstrap.jar -Dcatalina.base=/tomcat6/apache-tomcat-6.0.18 -Dcatalina.home=/tomcat6/apache-tomcat-6.0.18 -Djava.io.tmpdir=/tomcat6/apache-tomcat-6.0.18/temp org.apache.catalina.startup.Bootstrap start
root     28214 28183  0 10:02 pts/1    00:00:00 grep tomcat

[root@linux ~]# ps -ef | grep catalina | grep -v "grep catalina" |  grep -v "catalina.out"|awk '{print $2}' | head -1
7976

[root@linux ~]# fuser 8080/tcp
8080/tcp:             7976       -->> I need vice-versa of this. That is , by giving process id , i should get port number. I tried by grep of fuser but i couldn't find.

 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Session PID & socket connection pid

1. If I use an software application(which connects to the database in the server) in my local pc, how many PID should be registered? Would there be PID for the session and another PID for socket connection? 2. I noticed (through netstat) that when I logged in using the my software application,... (1 Reply)
Discussion started by: pcx26
1 Replies

2. HP-UX

To find pid from port number

Hi, I am working on HP-UX Release 11i. I want to find the process id (PID) of the process running on a particular port. lsof command fuser does not work on this system. Please suggest some alternative. Thanks (6 Replies)
Discussion started by: gmat
6 Replies

3. UNIX for Dummies Questions & Answers

pid from port number in AIX

Hello guys, How to shut down a port number in AIX. May be first I need to find out what is the process ID of that process that listens to this particular port.. Is there any command to find a process ID from the port number other than "lsof". thanks (1 Reply)
Discussion started by: solaix14
1 Replies

4. Shell Programming and Scripting

File exists, but cannot be opened.How to check- whether it could be opened to read when it exists

Hi #Testing for file existence if ; then echo 'SCHOOL data is available for processing' else echo 'SCHOOL DATA IS NOT AVAILABLE FOR PROCESSING' : i wrote a script, where it begins by checking if file exists or not. If it exists, it truncates the database... (2 Replies)
Discussion started by: rxg
2 Replies

5. UNIX for Dummies Questions & Answers

Find PID for a port

Hi, I need to find the PID for a given port on the below system. HP-UX mymachine B.11.31 U ia64 3223107173 unlimited-user license How can I ? (4 Replies)
Discussion started by: mohtashims
4 Replies

6. HP-UX

Find port for Pid

Hi, Is this the most appropriate way of finding the listen port number given the pid is "16659" ? lsof -Pan -i tcp -i udp | grep 16659 | grep -i "listen"If so, how can I extract "7001" and assign it to a variable say myport=7001 from the below output which happens to be actual port number? ... (1 Reply)
Discussion started by: mohtashims
1 Replies

7. UNIX for Advanced & Expert Users

Find PID using a Port?

Hi, I do not have root user credentials nor do I have the functional id of the process that uses port 80. How can I find the pid of the process using the port number 80 ? Operating System: Linux (6 Replies)
Discussion started by: mohtashims
6 Replies

8. Solaris

How to find port number wwn of particular port on dual port HBA,?

please find the below o/p for your reference bash-3.00# fcinfo hba-port HBA Port WWN: 21000024ff295a34 OS Device Name: /dev/cfg/c2 Manufacturer: QLogic Corp. Model: 375-3356-02 Firmware Version: 05.03.02 FCode/BIOS Version: BIOS: 2.02; fcode: 2.01;... (3 Replies)
Discussion started by: sb200
3 Replies
PLDD(1)                                                          Linux User Manual                                                         PLDD(1)

NAME
pldd - display dynamic shared objects linked into a process SYNOPSIS
pldd pid pldd option DESCRIPTION
The pldd command displays a list of the dynamic shared objects that are linked into the process with the specified process ID. The list includes the libraries that have been dynamically loaded using dlopen(3). OPTIONS
-?, --help Display program help message. --usage Display a short usage message. -V, --version Display the program version. EXIT STATUS
On success, pldd exits with the status 0. If the specified process does not exist, the user does not have permission to access its dynamic shared object list, or no command-line arguments are supplied, pldd exists with a status of 1. If given an invalid option, it exits with the status 64. VERSIONS
pldd is available since glibc 2.15. CONFORMING TO
The pldd command is not specified by POSIX.1. Some other systems have a similar command. NOTES
The command lsof -p PID also shows output that includes the dynamic shared objects that are linked into a process. The gdb(1) info shared command also shows the shared libraries being used by a process, so that one can obtain similar output to pldd using a command such as the following (to monitor the process with the specified pid): $ gdb -ex "set confirm off" -ex "set height 0" -ex "info shared" -ex "quit" -p $pid | grep '^0x.*0x' BUGS
Since glibc 2.19, pldd is broken: it just hangs when executed. It is unclear if it will ever be fixed. EXAMPLE
$ echo $$ # Display PID of shell 1143 $ pldd $$ # Display DSOs linked into the shell 1143: /usr/bin/bash linux-vdso.so.1 /lib64/libtinfo.so.5 /lib64/libdl.so.2 /lib64/libc.so.6 /lib64/ld-linux-x86-64.so.2 /lib64/libnss_files.so.2 SEE ALSO
ldd(1), lsof(1), dlopen(3), ld.so(8) COLOPHON
This page is part of release 4.15 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https://www.kernel.org/doc/man-pages/. GNU 2017-09-15 PLDD(1)
All times are GMT -4. The time now is 11:02 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy