Getting PID of Open Connectivity

Hi!

I've a Java socket server program that is listening for requests, and using netstat, I can see that the connection is already open.

However as the process name (from ps -ef) is very long and I can't grep the program name. Can anyone advise how I find out the PID of the process? Can netstat or some other command tell me that?

Thanks!

Regards
swing

fstat might help you here. In OpenBSD,

fstat | grep ':22' | awk '{print $3}' | uniq

This will search the fstat output for port 22, and then awk will give you the third column which is the PID for the process bound to the specified port. Replace 22 with whatever port number you are binding to (don't forget to leave in the colon symbol) and you should get the info you need. Column output and command line switches might be different! =)

Nick

lsof might be a better tool for what you are doing than netstat.

Hi! DraconianTimes & reborg

I forgot to mention that I'm on HP-UX 11i, and it doesn't seem to have fstat & lsof. Can you pls advise?

Thanks!

regards

well, take a quick tour at this

Hi andryk

Thanks! You've been a great help

cheers