linux中常用的查看后台进程ps命令
1、
-a: 列出所有用户
-u:列出状态
-x:列出更详细的信息
通常使用
ps -aux | grep "xxx" 查看特定的进程
ps -ef | grep “xxx”查看特定进程
示例:
root@PC1:/home/test# ps -aux | grep "admixture" ## 查看后台包含admixture关键字的进程 root 9499 100 0.3 60084 59500 pts/1 R+ 21:27 0:15 admixture --cv test.bed 20 root 9502 0.0 0.0 12116 660 pts/0 S+ 21:27 0:00 grep --color=auto admixture root@PC1:/home/test# ps -ef | grep "admixture" ## 查看后台包含admixture关键字的进程 root 9499 9160 99 21:27 pts/1 00:00:28 admixture --cv test.bed 20 root 9505 4371 0 21:27 pts/0 00:00:00 grep --color=auto admixture
2、对后台占用cpu的进程进行排序
root@PC1:/home/test# ps -aux --sort -pcpu | head ## 对后台占用cpu最多的进程进行排序 USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 9499 100 0.9 161344 160976 pts/1 R+ 21:27 2:32 admixture --cv test.bed 20 root 9439 99.9 0.2 181800 39884 pts/2 Sl+ 21:20 9:49 SNeP1.1 -ped outcome.ped rstudio+ 1121 0.1 0.0 175600 15632 ? Ssl 10:02 0:44 /usr/lib/rstudio-server/bin/rserver root 1 0.0 0.0 168936 12660 ? Ss 10:01 0:03 /sbin/init splash root 2 0.0 0.0 0 0 ? S 10:01 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? I< 10:01 0:00 [rcu_gp] root 4 0.0 0.0 0 0 ? I< 10:01 0:00 [rcu_par_gp] root 6 0.0 0.0 0 0 ? I< 10:01 0:00 [kworker/0:0H-events_highpri] root 7 0.0 0.0 0 0 ? I 10:01 0:17 [kworker/0:1-mm_percpu_wq]
3、对后台占用内存最多的进程进行排序
root@PC1:/home/test# ps -aux --sort -pmem | head ## 对后台占用内存最多的进程进行排序 USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1750 0.0 1.5 4092840 245300 ? Ssl 10:02 0:14 /usr/bin/gnome-shell root 9499 100 1.3 215248 214564 pts/1 R+ 21:27 4:02 admixture --cv test.bed 20 root 1906 0.0 0.3 642760 61260 ? Sl 10:02 0:00 /usr/libexec/evolution-data-server/evolution-alarm-notify root 1612 0.0 0.3 285356 60020 tty2 Sl+ 10:02 0:00 /usr/lib/xorg/Xorg vt2 -displayfd 3 -auth /run/user/0/gdm/Xauthority -background none -noreset -keeptty -verbose 3 root 1986 0.0 0.2 294452 41044 ? Sl 10:02 0:22 /usr/bin/vmtoolsd -n vmusr --blockFd 3 root 9439 100 0.2 181800 39884 pts/2 Sl+ 21:20 11:20 SNeP1.1 -ped outcome.ped root 2966 0.0 0.2 1465688 38496 ? Ssl 10:07 0:02 /usr/lib/snapd/snapd liujiax+ 2600 0.0 0.2 550584 37388 ? Sl 10:07 0:00 /usr/libexec/goa-daemon root 1829 0.0 0.2 550584 37012 ? Sl 10:02 0:00 /usr/libexec/goa-daemon
4、结合watch命令对占用cpu最高的进程进行动态监测
root@PC1:/home/test# watch -n 1 'ps -aux --sort -pcpu | head -5' ## 每个1秒刷新,输出占用cpu最高的五个进程 Every 1.0s: ps -aux --sort -pcpu | head -5 PC1: Sun May 1 21:38:50 2022 USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 9439 99.9 0.2 181800 33492 pts/2 Sl+ 21:20 18:38 SNeP1.1 -ped outcome.ped root 9697 99.5 1.2 208560 207964 pts/1 R+ 21:35 3:17 admixture --cv test.bed 20 root 9858 7.8 0.2 45208 36280 pts/3 D+ 21:37 0:07 sort root 9802 2.0 0.0 0 0 ? D 21:36 0:02 [kworker/u256:0+flush-8:0]
5、结合watch命令对占用内存最高的进程进行动态监测
root@PC1:/home/test# watch -n 1 'ps -aux --sort -pmem | head -5' ## 每隔1秒杀心,输出占用内存最高的五个进程 Every 1.0s: ps -aux --sort -pmem | head -5 PC1: Sun May 1 21:40:50 2022 USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1750 0.0 1.5 4092840 245300 ? Ssl 10:02 0:14 /usr/bin/gnome-shell root 9697 99.8 1.3 215248 214564 pts/1 R+ 21:35 5:16 admixture --cv test.bed 20 root 1906 0.0 0.3 642760 61260 ? Sl 10:02 0:00 /usr/libexec/evolution-data-server/evolution-alarm-notify root 1612 0.0 0.3 285356 60020 tty2 Sl+ 10:02 0:00 /usr/lib/xorg/Xorg vt2 -displayfd 3 -auth /run/user/0/gdm/Xauthori
6、同时对cpu和内存进行监测
root@PC1:/home/test# watch -n 1 'ps -aux --sort -pcpu,+pmem | head -5' ## 同时对cpu和内存进行监测 Every 1.0s: ps -aux --sort -pcpu,+pmem | head -5 PC1: Sun May 1 21:42:29 2022 USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 9439 100 0.2 181800 46428 pts/2 Sl+ 21:20 22:17 SNeP1.1 -ped outcome.ped root 9697 99.9 1.3 215248 214564 pts/1 R+ 21:35 6:55 admixture --cv test.bed 20 root 10382 49.8 0.2 45208 36416 pts/3 S+ 21:42 0:06 sort root 10383 9.9 0.1 28032 19164 pts/3 D+ 21:42 0:01 sort