top -pid 3907 -stats "pid,command,cpu"
-
-pid 3907
: seu ID de processo -
-stats pid,command,cpu
: mostra apenas o ID do processo, nome e% da CPU
Não é necessário executar awk
na saída.
Se você quiser pós-processar a saída, use -l 0
para executar no modo logging (0 significa indefinidamente, tudo o mais limita o número de amostras). A saída ficará assim (duas repetições):
Processes: 72 total, 3 running, 1 stuck, 68 sleeping, 326 threads
2011/05/10 19:15:13
Load Avg: 0.14, 0.14, 0.09
CPU usage: 20.0% user, 26.66% sys, 53.33% idle
SharedLibs: 5304K resident, 5208K data, 0B linkedit.
MemRegions: 16345 total, 1048M resident, 54M private, 338M shared.
PhysMem: 726M wired, 1802M active, 687M inactive, 3215M used, 750M free.
VM: 169G vsize, 1036M framework vsize, 5261732(0) pageins, 552476(0) pageouts.
Networks: packets: 46747406/52G in, 32528901/3715M out.
Disks: 9452898/244G read, 11226269/293G written.
PID COMMAND %CPU
3907 WindowServer 0.0
Processes: 72 total, 3 running, 1 stuck, 68 sleeping, 326 threads
2011/05/10 19:15:14
Load Avg: 0.13, 0.14, 0.09
CPU usage: 0.95% user, 1.90% sys, 97.14% idle
SharedLibs: 5304K resident, 5208K data, 0B linkedit.
MemRegions: 16346 total, 906M resident, 54M private, 386M shared.
PhysMem: 726M wired, 1802M active, 687M inactive, 3215M used, 751M free.
VM: 169G vsize, 1036M framework vsize, 5261732(0) pageins, 552476(0) pageouts.
Networks: packets: 46747406/52G in, 32528901/3715M out.
Disks: 9452898/244G read, 11226269/293G written.
PID COMMAND %CPU
3907 WindowServer 2.7
Use awk
ou uma ferramenta semelhante para exibir apenas a cada 13 linhas (como essas linhas contêm os valores nesse exemplo):
$ top -l 0 -pid 3907 -stats pid,command,cpu | awk 'NR%13==0'
3907 WindowServer 0.0
3907 WindowServer 1.3
3907 WindowServer 2.2