shouguol
(shouguol)
11
1、 使用三剑客提取指定pid的进程的cpu数据
top -n 1 -p 1 |grep -A 1 PID|awk '{print $10}'|sed ':1;N;s/\n/: /;b 1'
# 其实只有两行,sed不需要tag也是一样的
top -n 1 -p 1 |grep -A 1 PID|awk '{print $10}'|sed 'N;s/\n/: /'
2、for循环打印20次
for i in {1..20}; do
top -n 1 -p 1 |grep -A 1 PID|awk '{print $10}'|sed ':1;N;s/\n/: /;b 1'
sleep 1
done
1、使用三剑客提取指定pid的进程的cpu数据
top -n 1 -p 1 |awk ‘NR==8{print $10}’
2.使用三剑客提取指定pid的进程的cpu数据,打印20次,间隔1s(for循环来做)
for ((i=0;i<20;i++));do top -n 1 -p 1 |awk ‘NR==8{print $10}’;sleep 1;done
1、top -n 1 -p 535 | awk ‘NR==8 {print $11}’
2、for ((i=1; i<=20; i++)); do top -n 1 -p 535 | awk ‘NR==8 {print $11}’;sleep 1 ;done
pidstat | awk '/1113/{ print $9 }'
for i in $(seq 1 20);do pidstat | awk '/1113/{ print $9}';sleep 1;done
1、top -d 1 -n 20 -p 10|awk ‘NR==8{print $10}’
2、for i in {1…20}
> do
> top -d 1 -n 20 -p 10|awk ‘NR==8{print $10}’
> sleep 1
> done
ECLIPSE
(ECLIPSE)
20
作业1:
top -n 1 -p 1|grep systemd|awk ‘{print "systemd的%CPU: "$10}’
作业2:
for i in {1..20};do echo $(top -d 1 -n 1 -p 1|grep systemd|awk ‘{print "systemd的%CPU: "$10}’);sleep 1;done
1.使用三剑客提取指定pid的进程的cpu数据
top -p20 -n 1 |awk ‘NR==8{print $10,$11}’
2、 使用三剑客提取指定pid的进程的cpu数据,打印20次,间隔1s(for循环来做)
for ((i=0;i<20;i++)) ; do top -p20 -n 1 |awk ‘NR==8{print $10,$11}’;done
nancy
(杨亚楠)
24
1.使用三剑客提取指定pid的进程的cpu数据
2.使用三剑客提取指定pid的进程的cpu数据,打印20次,间隔1s(for循环来做)
whiteP
(whiteP)
25
1.使用三剑客提取指定pid的进程的cpu数据
top -p 23289 -n 1 | grep 23289 | awk ‘{print $10}’
2.使用三剑客提取指定pid的进程的cpu数据,打印20次,间隔1s(for循环来做)
for i in {1…20};do top -p 23289 -n 1 | grep 23289 | awk ‘{print $10}’;sleep 1;done
作业1.
使用三剑客提取指定pid的进程的cpu数据:
# 找出systemd的pid
$ ps -ef | grep '\b/systemd/\b' | awk '{print $3}' | uniq
# 提取cpu字段
$ top -n 1 -p 1 | grep systemd | awk '{print $10}'
作业2.
使用三剑客提取指定pid的进程的cpu数据,打印20次,间隔1s(for循环来做)
# 在作业1的基础上增加for循环
$ for i in {1..20};do top -n 1 -p 1 | grep systemd | awk '{print $10}';done
timothy
(提摩太)
27
1.使用三剑客提取指定 pid 的进程的 cpu 数据
ps -ef | grep docker
top -p 16430 -n 1 | grep 16430| awk '{print $10}'
2.使用三剑客提取指定 pid 的进程的 cpu 数据,打印 20 次,间隔 1s( for 循环来做)
for i in {1..20}
do
top -p 16430 -n 1 | grep 16430| awk '{print $10}'
sleep 1
done
使用三剑客提取指定pid的进程的cpu数据
ps -ef | grep systemd
使用三剑客提取指定pid的进程的cpu数据,打印20次,间隔1s(for循环来做)