Operating System - HP-UX
1862981 Members
1988 Online
110446 Solutions
New Discussion

Re: Another bit of scripting help needed

 
SOLVED
Go to solution
Wim Rombauts
Honored Contributor

Another bit of scripting help needed

Hello scripters, I need some help.

I have a few processes, all bases on the same exe, but started with different options.
All these processes start by listening on a TCP/IP port that I configure.

Now I want to find out which process is listening on what port.
With "ps -ef" I can't see the "port" option, because the command line is too long. I see all the same processes.
With "netstat -a" I can see someone is listening on those ports, but I cannot see the process that is doing it.

Can anyone of you help me to connect a listening TCP/IP-port to a process ID ?

Thanks in advance.

5 REPLIES 5
Bill Hassell
Honored Contributor

Re: Another bit of scripting help needed

The ps line length has been a problem for a long time, but there is an easy workaround: eliminate the full pathname for the executable by starting the processes with a cd to the directory and running the process with ./ as in:

cd /very/long/path ; ./program -options -moreOptions

The program you need to connect ports to processes is called lsof. Get a copy from: http://hpux.connect.org.uk/


Bill Hassell, sysadmin
Dagmar Boelen
Frequent Advisor

Re: Another bit of scripting help needed

Hi,

I think lsof should be able to do the trick. Lsof also lists the PID of process which has a certain connection open. It might be possible that you have to install it. I believe it is nog included in the standard hp-ux.
Bill Douglass
Esteemed Contributor

Re: Another bit of scripting help needed

As mentioned above, lsof wil do this trick.


lsof -i

will list all processes with open tcp or udp ports.

lsof -i:80

will list all processes connected or listening on port 80.

The full syntax woudd be

lsof -i [proto][@host|addr][:svc_list|port_list]
Bernhard Mueller
Honored Contributor
Solution

Re: Another bit of scripting help needed

In addition to what has been said:

in HP-UX 11i you have the -x option for ps to list the whole command line.

for HP-UX 11.0 there is a patch to enable this feature.

I believe it was PHCO_26274.

Regards,
Bernhard

Tim D Fulford
Honored Contributor

Re: Another bit of scripting help needed

lsof

OR, my favorite utility

glance, then do "F" & select process ID

Tim
-