【Linux】計算每位使用者的CPU與MEMORY使用量
#!/bin/bashif [ $1 -ne 5 ];then
sec=$1
else
sec=5
fiwhile true
do
clearps aux tail -n+2 awk \
'BEGIN { printf("\tUSER\t%MEM\t%CPU\n")}
{
CPU[$1] += $3
MEM[$1] += $4
}
END { for (USER in MEM)
{
printf("%12s %6.2f %6.2f\n", USER, MEM[USER], CPU[USER])
}
}'sleep $sec
done