PID and program name from netstat.

Hello All,

I am using netstat on HP-UX to retrieve the established network connections on my host. Can anyone please confirm how can I retrieve the PID and program name as well for these connections? These are available from the netstat version on Windows but I don't see PID and program name to be available from netstat on HP-UX.

Any help/pointers will be appreciated.

Thanks!

Hello Happy83,

Here is an example for same, you can take it as a first start up step and let us know if this helps.(Not tested though)

for i in `netstat -anp | grep "http" | awk '{print $7}' | awk -F '/' '{print $1}' | uniq` ;  do ps -eo pid,uid,ruser,etime | grep $i ; done

Thanks,
R. Singh

Is this from Hp-UX or some other OS?

Obviously HP-UX netstat only looks in the one system table, and does not look into other tables.
Maybe lsof can do this.? Download/install lsof from itrc

Hi Folks,

I guess usage of "lsof" needs super user priveleges. Is that correct?

Also, we need to run this netstat in a script on multiple HP-UX hosts in client's environment and we cant have lsof installed on each and every host. Is there any alternative to retrieve this?

Thanks.

I don't know a UNIX tool to list what programs have what ports, which doesn't require elevated privileges.

At least on Linux, "netstat -p" is doing that without requiring specific privileges.

But GNU's not UNIX. :wink:

It reports a pid of - unless run with root privileges.

1 Like

I have seen tools like lsof set up so users can use it (set-uid?), at least to see their own stuff. On most UNIX O/S you need lsof for this.

lsof will display if ran by user, connection from that user only, others will not be visible.

Regards
Peasant.

1 Like