如何才能从中获得进程名和PID解析netstat命令? [英] How to parse netstat command in order to get process name and PID from it?

查看:487
本文介绍了如何才能从中获得进程名和PID解析netstat命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图确定哪些应用程序正在使用特定端口,并获得 netstat的-tlnp | grep的<港口>为Linux

I'm trying to determine what application is using certain port and get netstat -tlnp | grep <port> for Linux.

此命令返回以下的输出:

This command return the following output:

(Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.)  
tcp  0  0 0.0.0.0:<port>  0.0.0.0:*  LISTEN  3591/java

我需要的结果只得到了处理和PID,即名称的java 3591。

I need to get in result only name of the process and PID, i.e java 3591.

什么是做的最好的方式?

What is best way to do it?

感谢您。

推荐答案

尝试

ps -p $(lsof -ti tcp:80) o comm=,pid=

netstat -tlnp | awk '/:80 */ {split($NF,a,"/"); print a[2],a[1]}'

这篇关于如何才能从中获得进程名和PID解析netstat命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆