首页 > 编程知识 正文

linux查看进程占用端口号,查看端口占用的进程

时间:2023-05-04 23:59:56 阅读:258969 作者:4770

1、netstat 命令 1.1、查看端口进程 1.1.1 -nlp netstat -nlp | grep 端口号

eg:

netstat -nlp | grep 3001

查询结果:

1.1.1 -anp netstat -anp | grep 端口号

eg:

netstat -anp | grep 3001

查询结果:

1.2、netstat 参数解析 usage: netstat [-veenNcCF] [<Af>] -r netstat {-V|--version|-h|--help} netstat [-vnNcaeol] [<Socket> ...] netstat { [-veenNac] -I[<Iface>] | [-veenNac] -i | [-cnNe] -M | -s } [delay] -r, --route display routing table #显示路由表 -I, --interfaces=<Iface> display interface table for <Iface> #显示网络接口表 -i, --interfaces display interface table #显示网络接口表 -g, --groups display multicast group memberships #显示多播组成员 -s, --statistics display networking statistics (like SNMP) #显示网络统计数据,如IP/ICMP/SNMP/..各协议统计。 -M, --masquerade display masqueraded connections #显示伪装的连接 -v, --verbose be verbose #详细信息 -n, --numeric don't resolve names #不做名字解析,不加此参数,80端口会显示成http,127.0.0.1显示成localhost,uid为0显示成root等等 --numeric-hosts don't resolve host names #不做主机名解析 --numeric-ports don't resolve port names #不做端口名解析 --numeric-users don't resolve user names #不做用户名解析 -N, --symbolic resolve hardware names -e, --extend display other/more information #显示更多信息,用户名,inode -p, --programs display PID/Program name for sockets #显示pid和程序名字 -c, --continuous continuous listing #持续的列出相关信息 -l, --listening display listening server sockets #显示处于监听状态的套接字 -a, --all, --listening display all sockets (default: connected) #显示所有的套接字 -o, --timers display timers #显示计时器 -F, --fib display Forwarding Information Base (default) #使用-rF查看路由表时,显示转发信息 -C, --cache display routing cache instead of FIB #使用-rC查看路由表时,显示详细的路由缓存 -T, --notrim stop trimming long addresses #停止修剪长地址 -t #显示tcp链接 -Z, --context display SELinux security context for sockets #显示套接字的SELINUX上下文-u #显示udp链接-x #显示unix套接字 <Iface>: Name of interface to monitor/list. <Socket>={-t|--tcp} {-u|--udp} {-S|--sctp} {-w|--raw} {-x|--unix} --ax25 --ipx --netrom <AF>=Use '-A <af>' or '--<af>'; default: inet List of possible address families (which support routing): inet (DARPA Internet) inet6 (IPv6) ax25 (AMPR AX.25) netrom (AMPR NET/ROM) ipx (Novell IPX) ddp (Appletalk DDP) x25 (CCITT X.25) 2、lsof 命令 2.1、查看端口进程 lsof -i:端口号

eg:

lsof -i:3001

查询结果:

2.2、lsof 参数解析

lsof语法格式是: lsof [options] filename
常用的参数列表:

lsof filename 显示打开指定文件的所有进程lsof -a 表示两个参数都必须满足时才显示结果lsof -c string 显示COMMAND列中包含指定字符的进程所有打开的文件lsof -u username 显示所属user进程打开的文件lsof -g gid 显示归属gid的进程情况lsof +d /DIR/ 显示目录下被进程打开的文件lsof +D /DIR/ 同上,但是会搜索目录下的所有目录,时间相对较长lsof -d FD 显示指定文件描述符的进程lsof -n 不将IP转换为hostname,缺省是不加上-n参数lsof -i 用以显示符合条件的进程情况lsof -i[46] [protocol][@hostname|hostaddr][:service|port]46 –> IPv4 or IPv6protocol –> TCP or UDPhostname –> Internet host namehostaddr –> IPv4地址service –> /etc/service中的 service name (可以不只一个)port –> 端口号 (可以不只一个) 3、查看端口占用进程 3.1、ps 命令 3.1.1 查看端口占用进程

  如果想详细查看这个进程,ID具体是哪一个进程,可以通过ps命令查看进程的详细信息。

ps -ef| grep 24809

eg:

ps -ef| grep 24809

查询结果:

3.1.1 ps 参数解析

使用方式:ps [options] [–help]
常用参数:

-A 显示所有进程(等价于-e)(utility)-a 显示一个终端的所有进程,除了会话引线-N 忽略选择。-d 显示所有进程,但省略所有的会话引线(utility)-x 显示没有控制终端的进程,同时显示各个命令的具体路径。dx不可合用。(utility)-p pid 进程使用cpu的时间-u uid or username 选择有效的用户id或者是用户名-g gid or groupname 显示组的所有进程。U username 显示该用户下的所有进程,且显示各个命令的详细路径。如:ps U zhang;(utility)-f 全部列出,通常和其他选项联用。如:ps -fa or ps -fx and so on.-l 长格式(有F,wchan,C 等字段)-j 作业格式-o 用户自定义格式。v 以虚拟存储器格式显示s 以信号格式显示-m 显示所有的线程-H 显示进程的层次(和其它的命令合用,如:ps -Ha)(utility)e 命令之后显示环境(如:ps -d e; ps -a e)(utility)h 不显示第一行 3.2、ll [option] 命令查看进程

通过 ll [option] 可以查看、可以快速定位到进程的目录。

ll /proc/进程ID/cwd

eg:

ll /proc/24809/cwd

查询结果:

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。