在批处理模式中运行以下命令按内存使用率对结果进行排序:
# top -bc -o +%MEM | head -n 20 -
top - 06:42:00 up 8 days, 20:25, 1 user, load average: 0.66, 0.74, 0.80 Tasks: 146 total, 1 running, 145 sleeping, 0 stopped, 0 zombie %Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 3880940 total, 1422044 free, 1059176 used, 1399720 buff/cache KiB Swap: 1048572 total, 514640 free, 533932 used. 2475984 avail Mem -
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 18105 mysql 20 0 1453900 156096 8816 S 0.0 4.0 2:12.98 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid 1841 root 20 0 228980 107036 5360 S 0.0 2.8 0:05.56 /usr/local/cpanel/3rdparty/perl/528/bin/perl -T -w /usr/local/cpanel/3rdparty/bin/spamd --max-children=3 --max-spare=1 --allowed-ips=127.0.0.+ 4301 root 20 0 230208 104608 1816 S 0.0 2.7 0:03.77 spamd child 8139 nobody 20 0 257000 27108 3408 S 0.0 0.7 0:00.04 /usr/sbin/httpd -k start 7961 nobody 20 0 256988 26912 3160 S 0.0 0.7 0:00.05 /usr/sbin/httpd -k start 8190 nobody 20 0 256976 26812 3140 S 0.0 0.7 0:00.05 /usr/sbin/httpd -k start 8353 nobody 20 0 256976 26812 3144 S 0.0 0.7 0:00.04 /usr/sbin/httpd -k start 8629 nobody 20 0 256856 26736 3108 S 0.0 0.7 0:00.02 /usr/sbin/httpd -k start 8636 nobody 20 0 256856 26712 3100 S 0.0 0.7 0:00.03 /usr/sbin/httpd -k start 8611 nobody 20 0 256844 25764 2228 S 0.0 0.7 0:00.01 /usr/sbin/httpd -k start 8451 nobody 20 0 256844 25760 2220 S 0.0 0.7 0:00.04 /usr/sbin/httpd -k start 8610 nobody 20 0 256844 25748 2224 S 0.0 0.7 0:00.01 /usr/sbin/httpd -k start 8632 nobody 20 0 256844 25744 2216 S 0.0 0.7 0:00.03 /usr/sbin/httpd -k start
上面命令的详细信息:
-b :批处理模式选项
-c :打印运行中的进程的绝对路径
-o :指定进行排序的字段
head :输出文件的第一部分
-n :打印前 n 行
3) 如何在批处理模式下运行 top 命令并按照指定的用户进程对结果进行排序
如果你想要按照指定用户进程对结果进行排序请运行以下命令:
# top -bc -u mysql | head -n 10 -
top - 06:44:58 up 8 days, 20:27, 1 user, load average: 0.99, 0.87, 0.84 Tasks: 140 total, 1 running, 137 sleeping, 0 stopped, 2 zombie %Cpu(s): 13.3 us, 3.3 sy, 0.0 ni, 83.3 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 3880940 total, 1589832 free, 885648 used, 1405460 buff/cache KiB Swap: 1048572 total, 514640 free, 533932 used. 2649412 avail Mem -
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 18105 mysql 20 0 1453900 156888 8816 S 0.0 4.0 2:16.42 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
4) 如何在批处理模式下运行 top 命令并按照处理时间进行排序
在批处理模式中使用以下 top 命令按照处理时间对结果进行排序。这展示了任务从启动以来已使用的总 CPU 时间。
但是如果你想要检查一个进程在 Linux 上运行了多长时间请看接下来的文章:
# top -bc -o TIME+ | head -n 20 -
top - 06:45:56 up 8 days, 20:28, 1 user, load average: 0.56, 0.77, 0.81 Tasks: 148 total, 1 running, 146 sleeping, 0 stopped, 1 zombie %Cpu(s): 0.0 us, 3.1 sy, 0.0 ni, 96.9 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 3880940 total, 1378664 free, 1094876 used, 1407400 buff/cache KiB Swap: 1048572 total, 514640 free, 533932 used. 2440332 avail Mem -
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 9 root 20 0 0 0 0 S 0.0 0.0 63:05.70 [rcu_sched] 272 root 20 0 0 0 0 S 0.0 0.0 16:12.13 [xfsaild/vda1] 3882 root 20 0 229832 6212 1220 S 0.0 0.2 9:00.84 /usr/sbin/httpd -k start 1 root 20 0 191144 2800 1596 S 0.0 0.1 5:43.75 /usr/lib/systemd/systemd --switched-root --system --deserialize 22 3761 root 20 0 68784 9820 2048 S 0.0 0.3 5:09.67 tailwatchd 3529 root 20 0 404380 3472 2604 S 0.0 0.1 3:24.98 /usr/sbin/rsyslogd -n 3520 root 20 0 574208 572 164 S 0.0 0.0 3:07.74 /usr/bin/python2 -Es /usr/sbin/tuned -l -P 444 dbus 20 0 58444 1144 612 S 0.0 0.0 2:23.90 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation 18105 mysql 20 0 1453900 157152 8816 S 0.0 4.0 2:17.29 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid 249 root 0 -20 0 0 0 S 0.0 0.0 1:28.83 [kworker/0:1H] 14 root 20 0 0 0 0 S 0.0 0.0 1:22.46 [ksoftirqd/1] 33 root 20 0 0 0 0 S 0.0 0.0 1:19.07 [kswapd0] 342 root 20 0 39472 2940 2752 S 0.0 0.1 1:18.17 /usr/lib/systemd/systemd-journald
5) 如何在批处理模式下运行 top 命令并将结果保存到文件中
(编辑:ASP站长网)
|