grep显示ps输出标题

您所在的位置:网站首页 ps指令linux grep显示ps输出标题

grep显示ps输出标题

2023-08-06 08:08| 来源: 网络整理| 查看: 265

背景 查找服务器上某个进程详细信息[ps:pid,ppid,内存使用,cpu使用等],常常会使用ps筛选对应的进程,正常情况过滤后信息不会显示ps输出的title。 实操: 1.未显示ps 标题

常规操作:ps aux|grep xx

[rootbird ~]# ps aux | grep libvirt dnsmasq 2169025 0.0 0.0 71964 2120 ? S 2021 0:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper root 2169026 0.0 0.0 71860 428 ? S 2021 0:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper root 3040675 0.0 0.0 12108 1068 pts/1 S+ 23:09 0:00 grep --color=auto libvirt 2.显示ps 标题

「通用法:使用ps的所有参数,例如:ps aux 、ps -ef」

ps aux| head -1;ps aux|grep xx [rootbird ~]# ps aux |head -1; ps aux| grep libvirt USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND dnsmasq 2169025 0.0 0.0 71964 2120 ? S 2021 0:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper root 2169026 0.0 0.0 71860 428 ? S 2021 0:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper root 3041792 0.0 0.0 12108 1060 pts/1 S+ 23:12 0:00 grep --color=auto libvirt

「动态调整,需要根据ps不同参数调整,例如:ps aux 、ps -ef」

ps aux|grep -E 'USER|xx' [rootbird ~]# ps auxw | grep -E "USER|libvirt" USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND dnsmasq 2169025 0.0 0.0 71964 2120 ? S 2021 0:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper root 2169026 0.0 0.0 71860 428 ? S 2021 0:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper root 3043012 0.0 0.0 12108 2484 pts/1 S+ 23:18 0:00 grep --color=auto -E USER|libvirt ps -ef|grep -E 'UID|xx' [rootbird ~]# ps -ef | grep -E "UID|libvirt" UID PID PPID C STIME TTY TIME CMD dnsmasq 2169025 1 0 2021 ? 00:00:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper root 2169026 2169025 0 2021 ? 00:00:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper root 3044818 3033179 0 23:26 pts/1 00:00:00 grep --color=auto -E UID|libvirt 实战

查找服务器上进程状况的时候[ps:D,Zone进程],ps aux 与ps -ef配合使用,分别显示各自title显的格外重要。

[rootbird ~]# ps -ef | grep -E "UID|libvirt" UID PID PPID C STIME TTY TIME CMD dnsmasq 2169025 1 0 2021 ? 00:00:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper root 2169026 2169025 0 2021 ? 00:00:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper root 3044818 3033179 0 23:26 pts/1 00:00:00 grep --color=auto -E UID|libvirt [rootbird ~]# ps aux | grep -E "USER|libvirt" USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND dnsmasq 2169025 0.0 0.0 71964 2120 ? S 2021 0:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper root 2169026 0.0 0.0 71860 428 ? S 2021 0:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper root 3045966 0.0 0.0 12108 2488 pts/1 S+ 23:32 0:00 grep --color=auto -E USER|libvirt

-------------------------------------------------工欲善其事,必先利其器--------------------------------------



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3