Re: How to find PIDs of processes listening on tcp ports?
- From: Dale Dellutri <ddelQQQlutr@xxxxxxxxxxxx>
- Date: Thu, 28 Dec 2006 19:41:06 +0000 (UTC)
On Thu, 28 Dec 2006 10:55:47 -0600 (CST), Steven M. Schweda <sms@xxxxxxxxxxxx> wrote:
From: Dale Dellutri <ddelQQQlutr@xxxxxxxxxxxx>
How can I find the PIDs of processes that are listening
on tcp ports?
I don't know of a simple command, but it should be possible to
process the output from "TCPIP SHOW DEVICE" to get the particular
"bgXXX" device, then 'f$getdvi( bg_name, "PID")'.
There's probably also a way to use F$DEVICE() and more clever
F$GETDVI() things to avoid "TCPIP SHOW DEVICE" altogether, but that
might require actual thought.
On Linux I can use
lsof -i
or
netstat -tanp
So, just port "lsof" to VMS. (How long could that take?)
It's not a port of lsof, but your clues above helped me to write
the following, which does enough of what I want. It's not
fully tested yet, but it _probably_ won't break anything.
=====TCPIP_INFO.COM=====
$! TCPIP_INFO.COM - Show useful info about tcpip connections and processes
$! Dale Dellutri 2007-12-28
$!
$ mypid = f$getjpi(0,"PID")
$ say = "WRITE SYS$OUTPUT"
$ assign /user_mode tcpip_info_'mypid'.lis sys$output
$ tcpip show device_socket
$ open /read /error=open_error f tcpip_info_'mypid'.lis.0
$read_loop:
$ read /end_of_file=read_eof /error=read_error f r
$ say r
$ d = f$element(2," ",r)
$ if d .eqs. "" then goto read_loop
$ pid = f$getdvi(d,"PID")
$ prcnam = f$getjpi(pid,"PRCNAM")
$ imagname = f$getjpi(pid,"IMAGNAME")
$ say " device:",d,", pid:",pid,", prcnam:",prcnam,", imagname:",imagname
$ goto read_loop
$read_eof:
$ close f
$ delete tcpip_info_'mypid'.lis.0
$ exit
$open_error:
$ say "Open error, status = ",$status
$ exit
$read_error:
$ say "Read error, status = ",$status
$ close f
$ exit
=====TCPIP_INFO.COM=====
--
Dale Dellutri <ddelQQQlutr@xxxxxxxxxxxx> (lose the Q's)
.
- References:
- Re: How to find PIDs of processes listening on tcp ports?
- From: Steven M. Schweda
- Re: How to find PIDs of processes listening on tcp ports?
- Prev by Date: Re: DECterm special escape sequences ?
- Next by Date: Re: Audio Cast #2 is now available
- Previous by thread: Re: How to find PIDs of processes listening on tcp ports?
- Next by thread: simple MOSAIC question
- Index(es):