惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
T
Threatpost
Latest news
Latest news
N
News | PayPal Newsroom
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Help Net Security
Help Net Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
AI
AI
Simon Willison's Weblog
Simon Willison's Weblog
TaoSecurity Blog
TaoSecurity Blog
The Last Watchdog
The Last Watchdog
L
LINUX DO - 热门话题
Google DeepMind News
Google DeepMind News
T
Threat Research - Cisco Blogs
O
OpenAI News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
The Exploit Database - CXSecurity.com
NISL@THU
NISL@THU
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
Securelist
小众软件
小众软件
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Martin Fowler
Martin Fowler
S
SegmentFault 最新的问题
Cisco Talos Blog
Cisco Talos Blog
云风的 BLOG
云风的 BLOG
AWS News Blog
AWS News Blog
GbyAI
GbyAI
N
News and Events Feed by Topic
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
美团技术团队
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
S
Schneier on Security
博客园 - 聂微东
V2EX - 技术
V2EX - 技术
T
Troy Hunt's Blog
SecWiki News
SecWiki News
S
Secure Thoughts
B
Blog RSS Feed
Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学
腾讯CDC
H
Heimdal Security Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Apple Machine Learning Research
Apple Machine Learning Research
月光博客
月光博客
www.infosecurity-magazine.com
www.infosecurity-magazine.com
P
Privacy International News Feed

博客园 - yeren2046

RedCoins,一个免费的类似bluecoins的个人财务管理软件 记录一个栈溢出导致的崩溃问题 一个免费的图片数据标注工具 常用zip命令 git版本导致的"Permission denied (publickey). fatal: Could not read from remote repository." linux 上用 core 文件定位线上问题 ffmpeg 时基转换 昇腾卡通道号范围 ffmpeg视频截取 英伟达硬解码错误汇总 DVPP问题汇总 TensorRT生成INT8校准文件 结构体指定初始化 ffmpeg命令行基于英伟达显卡编解码的转码 C++11 获取当前时间戳 基于CUDA查询显卡型号和显存大小 nvjpeg 简单使用 AV_PIX_FMT_CUDA 数据转 RGB C++ do{ } while(0)
只显示全部特定进程名的top信息的shell脚本
yeren2046 · 2025-11-07 · via 博客园 - yeren2046

1. 脚本代码

#!/bin/bash

# 使用 pgrep 获取所有名为 nginx 的进程的 PID,并用逗号分隔
EXE_NAME=$1

#包含名称即可
# NGINX_PIDS=$(pgrep -d, $EXE_NAME)
#名称必须完全匹配
NGINX_PIDS=$(pidof $EXE_NAME | tr ' ' ',')

# 检查是否找到任何进程
if [ -n "$NGINX_PIDS" ]; then
    # 使用 top 单次输出这些 PID 的信息
    top -b -n 1 -p  $NGINX_PIDS
else
    echo "No processes found with name '$EXE_NAME'."
fi

脚步文件命名为top.sh,注意给脚步添加可执行权限 chmod +x top.sh.

此脚步为单次输出信息.

2. 定时刷新

配合上watch命令,实现定时刷新信息

watch -n  0.1 ./top.sh demo

这里查看名称为demo的进程的top信息,每0.1s更新一次

效果如下:

top


ec878be9becfe6e164bdfb5ba75ca6815baf8e427cc615c1034e4daf432d4872

posted @ 2025-11-07 10:58  yeren2046  阅读(32)  评论(0)    收藏  举报