top -pid 3907 -stats "pid,command,cpu"
-pid 3907
: il tuo ID processo
-stats pid,command,cpu
: mostra solo ID processo, nome e% CPU
Non è necessario eseguire awk
l'output.
Se si desidera postelaborare l'output, utilizzare -l 0
per eseguire in modalità di registrazione (0 significa indefinitamente, tutto il resto limita il numero di campioni). L'output sarà simile al seguente (due ripetizioni):
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
Utilizzare awk
o uno strumento simile per visualizzare solo ogni 13a riga (poiché queste righe contengono i valori in quell'esempio):
$ 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
# top -p1 -stats "pid,command,cpu" top: unknown option 't'