开发者

Ploblem of This code(show pr0cess) [ps Linux]

This code show user's process load (%cpu)

ps aux | awk 'NR!=1{print $1}' | sort | un开发者_运维知识库iq | awk '{print "ps aux | grep "$1}' | awk '{printf $0; printf " | awk"; printf "{sum +="; print "$3}" }' | sed "s/{/ '{/g" | sed "s/3}/3} END {print \$1,sum}'/g" > 0.out

chmod 755 0.out

bash 0.out

This Code show same user in some OS(UBUNTU) example: root 11.5 root 0 root 0 root 1.8 root 1.3 root 0 root 1.1

but show different user(uniq) on some OS example2: root 11.5 daemon 0 syslog 0 ....

How can i write for example2 only.i want diff3rent user's %cpu.


You can replace all that with:

ps ahx -o "%U %C" | awk '
  {cpu[$1] += $2} 
  END {for (user in cpu) {print user, cpu[user]}}
'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜