So I log into a Solaris box, try to start Apache, and find that there is already a process listening on port 80, and it's not Apache. Our boxes don't have lsof installed, so I can't query with that. I guess I could do:
pfiles `ls /proc` | less
and look for "port: 80", but if anyone has a better solution, I'm all ears! Even better if I can look for the listening process without being root. I'm open to both shell and C solutions; I wouldn't mind having a little custom executable to carry with me for the next time this comes up.
Updated: I'm talking about generic installs of solaris for which I am not the administrator (although I do have superuser access), so installing things from the freeware disk isn't an option. Obviously neither are using Linux-specific extensions to fuser, netstat, or other tools. So far running pfiles on all processes seems to be the best solution, unfortunately. If that remains the case, I'll probably post an answer with some slightly more efficient code that the clip above.
Most probly sun's administrative server.. It's usually bundled along with sun's directory and a few other webmin-ish stuff that is in the default installation
I think the first answer is the best I wrote my own shell script developing this idea :
If you have access to
netstat
, that can do precisely that.From Solaris 11.2 onwards you can indeed do this with the
netstat
command. Have a look here. The-u
switch is what you are looking for.If you are on a lower version of Solaris then - as others have pointed out - the Solaris way of doing this is some kind of script wrapper around
pfiles
command. Beware though thatpfiles
command halts the process for a split second in order to inspect it. For 99.9% of processes this is unimportant. Unfortunately we have a process that will give a core dump if it is hit with apfiles
command so we are a bit cautious about using the command. Your situation may be totally different if you are in the 99.9%, meaning you can safely use thepfiles
command.Here's a one-liner:
'echo examining process PID' will be printed before each search, so once you see an output referencing port 80, you'll know which process is holding the handle.
Alternatively use:Since 'pfiles' might not like that you're trying to access other user's processes, unless you're root of course.