数码资讯
linux – 如何用ps过滤掉默认的系统进程?
选购提示
关注价格、性能、续航、售后和真实使用场景,理性比较后再下单。
有没有办法在
Linux系统上获取正在运行的进程列表,减去在每个系统上运行的默认进程(即只有在事后安装/执行的进程).
这可以用ps或任何类似工具完成吗?
这可以用ps或任何类似工具完成吗?
谢谢
默认情况下,系统进程可能意味着“守护进程”,如httpsd,nfsd等. ps输出中的TTY列是?对于守护进程.因此,为了排除这些,您可能需要根据您的知识在shell / perl中编写脚本这里我假设tty为第2列,因此根据您的输出,您可能想要更改它.
Perl的:
#!/usr/bin/perl
use strict;
use warnings;
open (PS,'ps aux |') or die "command can't execute $!"; # Runs command using pipe
while(<PS>){ # Run through pipe line by line
my $ttycol=(split) [2]; # get tty column from ps output
if($ttycol ne '?'){ # If col is ? then it's a daemon
print $_; # if not print
}
}
close(PS);
然后像“perl script.pl”一样运行它.
贝壳:
使用lain的输入,同样可以在shell脚本中实现
ps -ef | awk’$6!=“?” {打印}’
声明:本文内容用于数码产品信息整理与选购参考,具体价格、库存、售后政策以官方渠道和电商页面实时信息为准。