Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

常用linux进程查询命令 #15

Open
superleeyom opened this issue Jan 3, 2021 · 0 comments
Open

常用linux进程查询命令 #15

superleeyom opened this issue Jan 3, 2021 · 0 comments
Assignees

Comments

@superleeyom
Copy link
Owner

superleeyom commented Jan 3, 2021

ps 命令详解

ps命令详解

根据进程名查询进程信息

ps  -ef | grep {processName}

根据进程pid查询进程信息

ps  -ef | grep {pid}

根据端口查看对应进程信息

Linux

netstat -tunlp | grep {port}

示例:

# netstat -tunlp | grep 8080
tcp6       0      0 :::8080                 :::*                    LISTEN      29150/java

则 29150 为当前端口所对应的进程 pid

MacOS

lsof -i tcp:{port}

查看进程pid占用端口情况

Linux

netstat -nap | grep {pid}

MacOS

lsof -p {pid}|grep LISTEN

查询僵尸进程

ps -A -ostat,ppid,pid,cmd | grep -e '^[Zz]'
  • -A 参数列出所有进程
  • -o 自定义输出字段 我们设定显示字段为 stat(状态), ppid(进程父id), pid(进程id),cmd(命令)这四个参数
  • 因为状态为 z 或者 Z 的进程为僵尸进程,所以我们使用 grep 抓取 stat 状态为 z 或者 Z 进程

查看最消耗CPU和内存的进程

# 查看最消耗CPU的进程
ps -eo pid,ppid,%mem,%cpu,cmd --sort=-%cpu | head
# 查看最消耗内存的进程
ps -eo pid,ppid,%mem,%cpu,cmd --sort=-%mem | head
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant