vim test_cpu.sh
#!/bin/bash
LANG=C
PATH=/sbin:/usr/sbin:/bin:/usr/bin
interval=1
length=86400
for i in $(seq 1 $(expr ${length} / ${interval}));do
date
LANG=C ps -eT -o%cpu,pid,tid,ppid,comm | grep -v CPU | sort -n -r | head -20
date
LANG=C cat /proc/loadavg
{ LANG=C ps -eT -o%cpu,pid,tid,ppid,comm | sed -e 's/^ *//' | tr -s ' ' |
grep -v CPU | sort -n -r | cut -d ' ' -f 1 | xargs -I{} echo -n "{} + " &&
echo '0'; } | bc -l
sleep ${interval}
done
fuser -k $0
运行
[root@192-168-125-189 lysys]# sh test_cpu.sh
Wed Jun 1 15:46:58 CST 2022
0.3 3660 3660 3658 urlgrabber-ext-
0.2 3658 3658 2114 yum
0.0 8728 8728 8720 head
0.0 8727 8727 8720 sort
0.0 8726 8726 8720 grep
0.0 8725 8725 8720 ps
0.0 8720 8720 3884 sh
0.0 8716 8716 2 kworker/0:3
0.0 3989 3989 2 kworker/0:0
0.0 3903 3903 3882 sftp-server
0.0 3884 3884 3878 bash
0.0 3882 3882 1433 sshd
0.0 3878 3878 1433 sshd
0.0 3831 3831 2 kworker/0:2
0.0 3663 3663 3658 urlgrabber-ext-
0.0 3662 3662 3658 urlgrabber-ext-
0.0 3659 3659 3658 urlgrabber-ext-
0.0 3633 3633 2 kworker/0:1
Wed Jun 1 15:46:58 CST 2022
0.06 0.08 0.06 2/171 8730
.8
Wed Jun 1 15:46:59 CST 2022
5.0 8720 8720 3884 sh
0.3 3660 3660 3658 urlgrabber-ext-
0.2 3658 3658 2114 yum
0.0 8924 8924 8720 head
0.0 8923 8923 8720 sort
0.0 8922 8922 8720 grep
0.0 8921 8921 8720 ps
0.0 8716 8716 2 kworker/0:3
0.0 3989 3989 2 kworker/0:0
0.0 3903 3903 3882 sftp-server
0.0 3884 3884 3878 bash
0.0 3882 3882 1433 sshd
0.0 3878 3878 1433 sshd
0.0 3831 3831 2 kworker/0:2
0.0 3663 3663 3658 urlgrabber-ext-
0.0 3662 3662 3658 urlgrabber-ext-
0.0 3659 3659 3658 urlgrabber-ext-
0.0 3633 3633 2 kworker/0:1
Wed Jun 1 15:46:59 CST 2022
0.06 0.08 0.06 2/171 8926
5.8