« Females in computer science | Main | De-geeking signs »

fuser

Last night I was working on a machine that does not have lsof installed and wanted to find out what pid was holding a certain socket open.

Jeremy told me that fuser could do this. I never knew that... apparently neither did any other *nix geek I asked (work and friends).. how odd that nobody seems to know about this one.. but anyway.. for future reference, before I forget..

Works on linux not on solaris and hpux.
# fuser -n tcp 80

Will list pids which are using that port.. nifty..

output:
80/tcp: 945 9063 9064 9065 9066 9067 9072 9073 9074

Comments

Thanks for the tip. It will come in handy :-)

On the system with missing fuser you can find the same info with:
1. netstat -pa -- will report name and pid of main
process listening on the socked
2. ps -e -o ppid,pid and get only processes with
ppid equal to this from 1.

Or if you have pidof:
pidof `netstat -pan | grep :{YOUR_PORT} | awk -F'/' '{print $2}'`