I am trying to get processes attached with a port 7085 on SunOS. i tried following commands.
我试图在SunOS上使用端口7085连接进程。我尝试了以下命令。
netstat -ntlp | grep 7085
didn't return anything
netstat -ntlp | grep 7085没有返回任何东西
netstat -anop | grep 7085
tried this one also. This switches are not valid in SunOs
netstat -anop | grep 7085也尝试了这个。此开关在SunOs中无效
I am getting the following output.
我得到以下输出。
#netstat -anop
netstat: illegal option -- o
netstat:非法选项 - o
usage: netstat [-anv] [-f address_family]
用法:netstat [-anv] [-f address_family]
netstat [-n] [-f address_family] [-P protocol] [-g | -p | -s [interval [count]]]
netstat [-n] [-f address_family] [-P protocol] [-g | -p | -s [interval [count]]]
netstat -m [-v] [interval [count]]
netstat -m [-v] [interval [count]]
netstat -i [-I interface] [-an] [-f address_family] [interval [count]]
netstat -i [-I interface] [-an] [-f address_family] [interval [count]]
netstat -r [-anv] [-f address_family|filter]
netstat -r [-anv] [-f address_family | filter]
netstat -M [-ns] [-f address_family]
netstat -M [-ns] [-f address_family]
netstat -D [-I interface] [-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.
SunOS的版本是SunOS 5.10。我相信netstat是唯一能做到这一点的命令。
What is the exact switches for netstat which will give me the process id attached with port?
netstat的确切开关是什么,它会给我附加端口的进程ID?
3 个解决方案
#1
9
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.
pfiles / proc / *正在检索所有进程文件描述符的详细信息
2> / dev / null正在消除因瞬态过程而导致的错误
每行以数字开头后跟冒号报告进程ID和详细信息,它存储在awk pid变量中
当一行以字符串port:
Note: you need the required privilege(s) to get port information from processes you do not own (root has all privileges).
注意:您需要所需的权限才能从您不拥有的进程获取端口信息(root具有所有权限)。
#2
3
Have a look on lsof http://linux.about.com/library/cmd/blcmdl8_lsof.htm command.
看看lsof http://linux.about.com/library/cmd/blcmdl8_lsof.htm命令。
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 which is using it.
此命令描述哪些进程正在使用哪些文件描述符。请记住,端口7085上的任何内容都有自己的文件描述符,您可以使用它来追溯到正在使用它的进程。
I would try something like:
我会尝试类似的东西:
$ lsof -i :7085
Hope it can help.
希望它可以提供帮助。
#3
0
I got his script from HERE . Log into solaris system. Open vi editor. Go into insert mode. Copy and paste this script. save the file and give the name PCP. Give execute permission. Run this script with -p or -P swithc. It will give an output with the PID, PROCESS Name and Port.
我从这里得到了他的剧本。登录solaris系统。打开vi编辑器。进入插入模式。复制并粘贴此脚本。保存文件并命名为PCP。授予执行权限。使用-p或-P swithc运行此脚本。它将输出PID,PROCESS Name和Port。
Make sure you need to be in ksh shell to execute it.
确保你需要在ksh shell中执行它。
PCP is a script that enables administrators to see what open TCP ports are in use on a Solaris system. It maps ports to PIDs and vice versa. It accepts wildcards and will also show at a glance all open ports and their corresponding PIDs. It is nice script gives a very fine out put. Just try it.
PCP是一个脚本,使管理员能够查看Solaris系统上正在使用的打开TCP端口。它将端口映射到PID,反之亦然。它接受通配符,并且还会一目了然地显示所有打开的端口及其相应的PID。这是一个很好的脚本给出了一个非常精细的输出。就试一试吧。
Example: #pcp -p PORT_NUMBER or #pcp -P PROCESS_ID
示例:#pcp -p PORT_NUMBER或#pcp -P PROCESS_ID
#!/usr/bin/ksh
#
# # PCP (PID con Port)
# v1.10 08/10/2010 Sam Nelson sam @ unix.ms
#
# If you have a Solaris 8, 9 or 10 box and you can't
# install lsof, try this. It maps PIDS to ports and vice versa.
# It also shows you which peers are connected on which port.
# Wildcards are accepted for -p and -P options.
#
# Many thanks Daniel Trinkle trinkle @ cs.purdue.edu
# for the help, much appreciated.
#
i=0
while getopts :p:P:a opt
do
case "${opt}" in
p ) port="${OPTARG}";i=3;;
P ) pid="${OPTARG}";i=3;;
a ) all=all;i=2;;
esac
done
if [ $OPTIND != $i ]
then
echo >&2 "usage: $0 [-p PORT] [-P PID] [-a] (Wildcards OK) "
exit 1
fi
shift `expr $OPTIND - 1`
if [ "$port" ]
then
# Enter the port number, get the PID
#
port=${OPTARG}
echo "PID\tProcess Name and Port"
echo "_________________________________________________________"
for proc in `ptree -a | awk '/ptree/ {next} {print $1};'`
do
result=`pfiles $proc 2> /dev/null| egrep "port: $port$"`
if [ ! -z "$result" ]
then
program=`ps -fo comm= -p $proc`
echo "$proc\t$program\t$port\n$result"
echo "_________________________________________________________"
fi
done
elif [ "$pid" ]
then
# Enter the PID, get the port
#
pid=$OPTARG
# Print out the information
echo "PID\tProcess Name and Port"
echo "_________________________________________________________"
for proc in `ptree -a | awk '/ptree/ {next} $1 ~ /^'"$pid"'$/ {print $1};'`
do
result=`pfiles $proc 2> /dev/null| egrep port:`
if [ ! -z "$result" ]
then
program=`ps -fo comm= -p $proc`
echo "$proc\t$program\n$result"
echo "_________________________________________________________"
fi
done
elif [ $all ]
then
# Show all PIDs, Ports and Peers
#
echo "PID\tProcess Name and Port"
echo "_________________________________________________________"
for proc in `ptree -a | sort -n | awk '/ptree/ {next} {print $1};'`
do
out=`pfiles $proc 2>/dev/null| egrep "port:"`
if [ ! -z "$out" ]
then
name=`ps -fo comm= -p $proc`
echo "$proc\t$name\n$out"
echo "_________________________________________________________"
fi
done
fi
exit 0
#1
9
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.
pfiles / proc / *正在检索所有进程文件描述符的详细信息
2> / dev / null正在消除因瞬态过程而导致的错误
每行以数字开头后跟冒号报告进程ID和详细信息,它存储在awk pid变量中
当一行以字符串port:
Note: you need the required privilege(s) to get port information from processes you do not own (root has all privileges).
注意:您需要所需的权限才能从您不拥有的进程获取端口信息(root具有所有权限)。
#2
3
Have a look on lsof http://linux.about.com/library/cmd/blcmdl8_lsof.htm command.
看看lsof http://linux.about.com/library/cmd/blcmdl8_lsof.htm命令。
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 which is using it.
此命令描述哪些进程正在使用哪些文件描述符。请记住,端口7085上的任何内容都有自己的文件描述符,您可以使用它来追溯到正在使用它的进程。
I would try something like:
我会尝试类似的东西:
$ lsof -i :7085
Hope it can help.
希望它可以提供帮助。
#3
0
I got his script from HERE . Log into solaris system. Open vi editor. Go into insert mode. Copy and paste this script. save the file and give the name PCP. Give execute permission. Run this script with -p or -P swithc. It will give an output with the PID, PROCESS Name and Port.
我从这里得到了他的剧本。登录solaris系统。打开vi编辑器。进入插入模式。复制并粘贴此脚本。保存文件并命名为PCP。授予执行权限。使用-p或-P swithc运行此脚本。它将输出PID,PROCESS Name和Port。
Make sure you need to be in ksh shell to execute it.
确保你需要在ksh shell中执行它。
PCP is a script that enables administrators to see what open TCP ports are in use on a Solaris system. It maps ports to PIDs and vice versa. It accepts wildcards and will also show at a glance all open ports and their corresponding PIDs. It is nice script gives a very fine out put. Just try it.
PCP是一个脚本,使管理员能够查看Solaris系统上正在使用的打开TCP端口。它将端口映射到PID,反之亦然。它接受通配符,并且还会一目了然地显示所有打开的端口及其相应的PID。这是一个很好的脚本给出了一个非常精细的输出。就试一试吧。
Example: #pcp -p PORT_NUMBER or #pcp -P PROCESS_ID
示例:#pcp -p PORT_NUMBER或#pcp -P PROCESS_ID
#!/usr/bin/ksh
#
# # PCP (PID con Port)
# v1.10 08/10/2010 Sam Nelson sam @ unix.ms
#
# If you have a Solaris 8, 9 or 10 box and you can't
# install lsof, try this. It maps PIDS to ports and vice versa.
# It also shows you which peers are connected on which port.
# Wildcards are accepted for -p and -P options.
#
# Many thanks Daniel Trinkle trinkle @ cs.purdue.edu
# for the help, much appreciated.
#
i=0
while getopts :p:P:a opt
do
case "${opt}" in
p ) port="${OPTARG}";i=3;;
P ) pid="${OPTARG}";i=3;;
a ) all=all;i=2;;
esac
done
if [ $OPTIND != $i ]
then
echo >&2 "usage: $0 [-p PORT] [-P PID] [-a] (Wildcards OK) "
exit 1
fi
shift `expr $OPTIND - 1`
if [ "$port" ]
then
# Enter the port number, get the PID
#
port=${OPTARG}
echo "PID\tProcess Name and Port"
echo "_________________________________________________________"
for proc in `ptree -a | awk '/ptree/ {next} {print $1};'`
do
result=`pfiles $proc 2> /dev/null| egrep "port: $port$"`
if [ ! -z "$result" ]
then
program=`ps -fo comm= -p $proc`
echo "$proc\t$program\t$port\n$result"
echo "_________________________________________________________"
fi
done
elif [ "$pid" ]
then
# Enter the PID, get the port
#
pid=$OPTARG
# Print out the information
echo "PID\tProcess Name and Port"
echo "_________________________________________________________"
for proc in `ptree -a | awk '/ptree/ {next} $1 ~ /^'"$pid"'$/ {print $1};'`
do
result=`pfiles $proc 2> /dev/null| egrep port:`
if [ ! -z "$result" ]
then
program=`ps -fo comm= -p $proc`
echo "$proc\t$program\n$result"
echo "_________________________________________________________"
fi
done
elif [ $all ]
then
# Show all PIDs, Ports and Peers
#
echo "PID\tProcess Name and Port"
echo "_________________________________________________________"
for proc in `ptree -a | sort -n | awk '/ptree/ {next} {print $1};'`
do
out=`pfiles $proc 2>/dev/null| egrep "port:"`
if [ ! -z "$out" ]
then
name=`ps -fo comm= -p $proc`
echo "$proc\t$name\n$out"
echo "_________________________________________________________"
fi
done
fi
exit 0