how to get process id attached with particular port in sunos
Solution 1
pfiles /proc/* 2>/dev/null | nawk '
/^[0-9]*:/ { pid=$0 }
/port: 7085$/ { printf("%s %s\n",pid,$0);}'
-
pfiles /proc/*
is retrieving all processes file descriptors details -
2>/dev/null
is dropping out errors due to transient processes died in the meantime - each line starting with a number followed by a colon reports the process id and details, it is stored in the awk pid variable
- when a line ends with the string
port: <portnumber>
(here is 7085), the corresponding pid variable is displayed.
Note: you need the required privilege(s) to get port information from processes you do not own (root has all privileges).
Solution 2
Have a look on lsof
http://linux.about.com/library/cmd/blcmdl8_lsof.htm command.
This command describes which processes are using which file descriptors. Remember that anything on port 7085 will have its own file descriptor which you can use to trace back to the process using it.
I would try something like:
$ lsof -i :7085
Hope it can help.
LOGAN
I am computer engineer working in a MNC company as a application engineer. I like to on production issues which is all about real time networking issues, application issues.
Updated on July 19, 2020Comments
-
LOGAN almost 4 years
I am trying to get processes attached with a port 7085 on SunOS. i tried following commands.
netstat -ntlp | grep 7085
didn't return anythingnetstat -anop | grep 7085
tried this one also. This switches are not valid in SunOsI am getting the following output.
#netstat -anop
netstat: illegal option -- o
usage: netstat [-anv] [-f address_family]
netstat [-n] [-f address_family] [-P protocol] [-g | -p | -s [interval [count]]]
netstat -m [-v] [interval [count]]
netstat -i [-I interface] [-an] [-f address_family] [interval [count]]
netstat -r [-anv] [-f address_family|filter]
netstat -M [-ns] [-f address_family]
netstat -D [-I interface] [-f address_family]
The version of SunOS is SunOS 5.10. I believe netstat is the only command can do this.
What is the exact switches for netstat which will give me the process id attached with port?
-
LOGAN over 11 yearsYes. I tried that unfortunately the command was not available. I would have installed this package but it is production server and i dont have rights to install anything on the server and there is not only 1 server there are more than 200+ servers. I am trying get a help with the available commands on solaris...
-
andrefsp over 11 years@LOGAN Have you got fuser? Try this one: fuser -4 -v -n tcp 7085
-
LOGAN over 11 yearsit is not working. I got following out put.fuser: illegal option -- 4
Illegal option ?. Usage: fuser [-[k|s sig]un[c|f|d]] files [-[[k|s sig]un[c|f|d]] files]..
-
jlliagre over 11 yearsStripping out the author/credit names is a poor practice. unix.ms/pcp
-
LOGAN over 11 yearsdidn't work for me. command didn't return anything after few seconds.
-
LOGAN over 11 yearsthe script i am using internally it is using pfiles to get the details.
-
LOGAN over 11 years@jiliagre. This one is working fine as expected. If you can give an explanation of this script, it will be possible for me to change it as per my needs in future..