用ps -elf或者ps aux来查看进程
user:用户
pid:子进程号
ppid:父进程号
%cpu:cup百分占比
%MEM:内存百分占比
VSZ:虚拟内存
RSS:实际占用物理内存
TTY:终端,TTY1代表图形化界面,TTY2-6代表字符界面,PTS代表通过远程连接,?代表没有终端。
STAT:S可中断睡眠,D不可中断睡眠,R运行状态,Z僵死状态,T停止状态,s控制性进程,<高优先级,N低优先级,l多线程,+当前进程运行前台。
COMMAND:命令,带[ ]是内核态,不带[ ]是用户态
top查看实时进程
默认以CPU降序排列,M是内存降序,P是CPU降序,N是pid降序排列,s改变更新时间
字段up是运行时间
load average:平均负载,越大说明等待运行的越多
ps按占用内存百分比从大到小排列
[root@localhost ~]# ps aux | sort -n -r -k 4|head
root 72266 0.0 0.0 108176 660 pts/0 S+ 19:49 0:00 head
root 72265 0.0 0.0 122644 924 pts/0 S+ 19:49 0:00 sort -n -r -k 2
root 72264 0.0 0.1 155360 1892 pts/0 R+ 19:49 0:00 ps aux
root 72260 0.0 0.0 0 0 ? S 19:49 0:00 [kworker/1:0]
root 72237 0.1 0.3 350468 6548 ? Sl 19:49 0:00 /usr/sbin/abrt-dbus -t133
root 72216 0.5 0.1 116652 3268 pts/0 Ss 19:49 0:00 -bash
root 72210 2.1 0.3 160848 5616 ? Ss 19:49 0:00 sshd: root@pts/0
root 72209 0.0 0.0 107952 360 ? S 19:49 0:00 sleep 60
root 16998 0.0 0.0 0 0 ? S 19:40 0:00 [kworker/1:1]
root 16808 0.0 0.0 0 0 ? S 19:20 0:00 [kworker/1:2]
查找到某一个进程的pid有几种方式
[root@localhost ~]# ps aux | grep vim | grep -v grep
root 72410 7.5 0.2 151888 5440 pts/1 S+ 19:56 0:00 vim test
[root@localhost ~]# pgrep -l vim
72410 vim
[root@localhost ~]# ps -axo pid,command |grep vim | grep -v grep
72410 vim test
[root@localhost ~]# pstree -up | grep vim
| `-sshd(72360)---bash(72368)---vim(72410)
统计出root用户一共运行的进程总数
[root@localhost ~]# ps -axo user,stat |grep root|grep R |wc -l
1
统计出系统当中所有正在正常运行的进程数
[root@localhost ~]# ps -axo stat |grep R |wc -l
1
查看httpd一共启动了几个进程并全部杀死
[root@localhost ~]# pgrep httpd |wc -l
6
[root@localhost ~]# kill `pgrep httpd`
[root@localhost ~]# pgrep httpd |wc -l
0
查看当前用户的所有进程的详细信息
[root@localhost ~]# ps -ux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.3 193972 7036 ? Ss 18:18 0:01 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
root 2 0.0 0.0 0 0 ? S 18:18 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S 18:18 0:00 [ksoftirqd/0]
root 5 0.0 0.0 0 0 ? S< 18:18 0:00 [kworker/0:0H]
root 7 0.0 0.0 0 0 ? S 18:18 0:00 [migration/0]
root 8 0.0 0.0 0 0 ? S 18:18 0:00 [rcu_bh]
root 9 0.0 0.0 0 0 ? S 18:18 0:01 [rcu_sched]
root 10 0.0 0.0 0 0 ? S< 18:18 0:00 [lru-add-drain]
root 11 0.0 0.0 0 0 ? S 18:18 0:00 [watchdog/0]
root 12 0.0 0.0 0 0 ? S 18:18 0:00 [watchdog/1]
root 13 0.0 0.0 0 0 ? S 18:18 0:00 [migration/1]
root 14 0.0 0.0 0 0 ? S 18:18 0:00 [ksoftirqd/1]
root 16 0.0 0.0 0 0 ? S< 18:18 0:00 [kworker/1:0H]
root 17 0.0 0.0 0 0 ? S 18:18 0:00 [watchdog/2]
root 18 0.0 0.0 0 0 ? S 18:18 0:00 [migration/2]
root 19 0.0 0.0 0 0 ? S 18:18 0:00 [ksoftirqd/2]
root 21 0.0 0.0 0 0 ? S< 18:18 0:00 [kworker/2:0H]
root 22 0.0 0.0 0 0 ? S 18:18 0:00 [watchdog/3]
root 23 0.0 0.0 0 0 ? S 18:18 0:00 [migration/3]
root 24 0.0 0.0 0 0 ? S 18:18 0:00 [ksoftirqd/3]
root 26 0.0 0.0 0 0 ? S< 18:18 0:00 [kworker/3:0H]
root 28 0.0 0.0 0 0 ? S 18:18 0:00 [kdevtmpfs]
root 29 0.0 0.0 0 0 ? S< 18:18 0:00 [netns]
root 30 0.0 0.0 0 0 ? S 18:18 0:00 [khungtaskd]
root 31 0.0 0.0 0 0 ? S< 18:18 0:00 [writeback]
root 32 0.0 0.0 0 0 ? S< 18:18 0:00 [kintegrityd]
root 33 0.0 0.0 0 0 ? S< 18:18 0:00 [bioset]
root 34 0.0 0.0 0 0 ? S< 18:18 0:00 [bioset]
root 35 0.0 0.0 0 0 ? S< 18:18 0:00 [bioset]
root 36 0.0 0.0 0 0 ? S< 18:18 0:00 [kblockd]
root 37 0.0 0.0 0 0 ? S< 18:18 0:00 [md]
root 38 0.0 0.0 0 0 ? S< 18:18 0:00 [edac-poller]
root 39 0.0 0.0 0 0 ? S< 18:18 0:00 [watchdogd]
root 40 0.0 0.0 0 0 ? S 18:18 0:00 [kworker/2:1]
root 41 0.0 0.0 0 0 ? S 18:18 0:00 [kworker/3:1]
root 48 0.0 0.0 0 0 ? S 18:18 0:00 [kswapd0]
root 49 0.0 0.0 0 0 ? SN 18:18 0:00 [ksmd]
root 50 0.0 0.0 0 0 ? SN 18:18 0:00 [khugepaged]
root 51 0.0 0.0 0 0 ? S< 18:18 0:00 [crypto]
root 59 0.0 0.0 0 0 ? S< 18:18 0:00 [kthrotld]
root 61 0.0 0.0 0 0 ? S< 18:18 0:00 [kmpath_rdacd]
root 62 0.0 0.0 0 0 ? S< 18:18 0:00 [kaluad]
root 63 0.0 0.0 0 0 ? S< 18:18 0:00 [kpsmoused]
root 64 0.0 0.0 0 0 ? S 18:18 0:01 [kworker/0:2]
root 65 0.0 0.0 0 0 ? S< 18:18 0:00 [ipv6_addrconf]
root 78 0.0 0.0 0 0 ? S< 18:18 0:00 [deferwq]
root 109 0.0 0.0 0 0 ? S 18:18 0:00 [kauditd]
root 515 0.0 0.0 0 0 ? S 18:18 0:00 [kworker/3:2]
root 666 0.0 0.0 0 0 ? S< 18:18 0:00 [ata_sff]
root 698 0.0 0.0 0 0 ? S 18:18 0:00 [scsi_eh_0]
root 713 0.0 0.0 0 0 ? S< 18:18 0:00 [scsi_tmf_0]
root 718 0.0 0.0 0 0 ? S 18:18 0:00 [scsi_eh_1]
root 719 0.0 0.0 0 0 ? S< 18:18 0:00 [scsi_tmf_1]
root 750 0.0 0.0 0 0 ? S< 18:18 0:00 [mpt_poll_0]
root 759 0.0 0.0 0 0 ? S< 18:18 0:00 [mpt/0]
root 1025 0.0 0.0 0 0 ? S 18:18 0:00 [scsi_eh_2]
root 1031 0.0 0.0 0 0 ? S< 18:18 0:00 [scsi_tmf_2]
root 1189 0.0 0.0 0 0 ? S< 18:18 0:00 [ttm_swap]
root 1198 0.0 0.0 0 0 ? S 18:18 0:00 [irq/16-vmwgfx]
root 1683 0.0 0.0 0 0 ? S< 18:18 0:00 [nfit]
root 2920 0.0 0.0 0 0 ? S< 18:18 0:00 [bioset]
root 2924 0.0 0.0 0 0 ? S< 18:18 0:00 [xfsalloc]
root 2928 0.0 0.0 0 0 ? S< 18:18 0:00 [xfs_mru_cache]
root 2936 0.0 0.0 0 0 ? S< 18:18 0:00 [xfs-buf/sda3]
root 2939 0.0 0.0 0 0 ? S< 18:18 0:00 [xfs-data/sda3]
root 2940 0.0 0.0 0 0 ? S< 18:18 0:00 [xfs-conv/sda3]
root 2942 0.0 0.0 0 0 ? S< 18:18 0:00 [xfs-cil/sda3]
root 2943 0.0 0.0 0 0 ? S< 18:18 0:00 [xfs-reclaim/sda]
root 2944 0.0 0.0 0 0 ? S< 18:18 0:00 [xfs-log/sda3]
root 2945 0.0 0.0 0 0 ? S< 18:18 0:00 [xfs-eofblocks/s]
root 2946 0.0 0.0 0 0 ? S 18:18 0:00 [xfsaild/sda3]
root 2947 0.0 0.0 0 0 ? S< 18:18 0:00 [kworker/0:1H]
root 3020 0.0 0.2 39328 3912 ? Ss 18:18 0:00 /usr/lib/systemd/systemd-journald
root 3041 0.0 0.2 119152 4068 ? Ss 18:18 0:00 /usr/sbin/lvmetad -f
root 3056 0.0 0.3 48860 6184 ? Ss 18:18 0:00 /usr/lib/systemd/systemd-udevd
root 5224 0.0 0.0 0 0 ? S< 18:18 0:00 [xfs-buf/sda1]
root 5237 0.0 0.0 0 0 ? S< 18:18 0:00 [xfs-data/sda1]
root 5241 0.0 0.0 0 0 ? S< 18:18 0:00 [xfs-conv/sda1]
root 5243 0.0 0.0 0 0 ? S< 18:18 0:00 [xfs-cil/sda1]
root 5292 0.0 0.0 0 0 ? S< 18:18 0:00 [xfs-reclaim/sda]
root 5301 0.0 0.0 0 0 ? S< 18:18 0:00 [xfs-log/sda1]
root 5307 0.0 0.0 0 0 ? S< 18:18 0:00 [xfs-eofblocks/s]
root 5315 0.0 0.0 0 0 ? S 18:18 0:00 [xfsaild/sda1]
root 5879 0.0 0.0 0 0 ? S< 18:18 0:00 [kvm-irqfd-clean]
root 6035 0.0 0.0 62044 1080 ? S<sl 18:18 0:00 /sbin/auditd
root 6037 0.0 0.0 84552 920 ? S<sl 18:18 0:00 /sbin/audispd
root 6039 0.0 0.0 55628 1400 ? S< 18:18 0:00 /usr/sbin/sedispatch
root 6041 0.0 0.0 0 0 ? S< 18:18 0:00 [rpciod]
root 6042 0.0 0.0 0 0 ? S< 18:18 0:00 [xprtiod]
root 6068 0.0 0.1 90392 3208 ? Ss 18:18 0:00 /sbin/rngd -f
root 6072 0.0 0.4 453332 8320 ? Ssl 18:18 0:00 /usr/libexec/udisks2/udisksd
root 6074 0.0 0.0 21676 1296 ? Ss 18:18 0:00 /usr/sbin/irqbalance --foreground
root 6075 0.0 0.3 99568 6124 ? Ss 18:18 0:00 /usr/bin/VGAuthService -s
root 6076 0.0 0.1 24492 2280 ? Ss 18:18 0:00 /usr/sbin/smartd -n -q never
root 6077 0.0 0.3 228084 5648 ? Ss 18:18 0:00 /usr/sbin/abrtd -d -s
root 6079 0.0 0.2 225796 4892 ? Ss 18:18 0:00 /usr/bin/abrt-watch-log -F BUG: WARNING: at WARNING: CPU: INFO: possible recursive locking detected ernel BUG at list_del corruption list_add c
root 6080 0.0 0.2 225796 4892 ? Ss 18:18 0:00 /usr/bin/abrt-watch-log -F Backtrace /var/log/Xorg.0.log -- /usr/bin/abrt-dump-xorg -xD
root 6081 0.0 0.2 396568 4260 ? Ssl 18:18 0:00 /usr/libexec/accounts-daemon
root 6088 0.1 0.3 320216 6880 ? Ssl 18:18 0:06 /usr/bin/vmtoolsd
root 6093 0.0 0.2 430600 5536 ? Ssl 18:18 0:00 /usr/sbin/ModemManager
root 6100 0.0 0.0 16892 1400 ? SNs 18:18 0:00 /usr/sbin/alsactl -s -n 19 -c -E ALSA_CONFIG_PATH=/etc/alsa/alsactl.conf --initfile=/lib/alsa/init/00main rdaemon
root 6121 0.0 0.0 0 0 ? S< 18:18 0:00 [kworker/2:1H]
root 6122 0.0 0.0 207828 1488 ? Ssl 18:18 0:00 /usr/sbin/gssproxy -D
root 6175 0.0 0.0 26580 1836 ? Ss 18:18 0:00 /usr/lib/systemd/systemd-logind
root 6222 0.0 0.0 115304 956 ? S 18:18 0:00 /bin/bash /usr/sbin/ksmtuned
root 6460 0.0 0.2 112756 4308 ? Ss 18:18 0:00 /usr/sbin/sshd -D
root 6463 0.0 0.9 573824 17276 ? Ssl 18:18 0:01 /usr/bin/python2 -Es /usr/sbin/tuned -l -P
root 6464 0.0 0.2 197880 4208 ? Ss 18:18 0:00 /usr/sbin/cupsd -f
root 6466 0.0 0.3 216408 6252 ? Ssl 18:18 0:00 /usr/sbin/rsyslogd -n
root 6470 0.0 0.9 1006584 18476 ? Ssl 18:18 0:00 /usr/sbin/libvirtd
root 6475 0.0 0.2 481472 4636 ? Ssl 18:18 0:00 /usr/sbin/gdm
root 6479 0.0 0.0 126288 1712 ? Ss 18:18 0:00 /usr/sbin/crond -n
root 6480 0.0 0.0 25904 944 ? Ss 18:18 0:00 /usr/sbin/atd -f
root 6541 0.0 1.4 318124 27512 tty1 Ssl+ 18:18 0:00 /usr/bin/X :0 -background none -noreset -audit 4 -verbose -auth /run/gdm/auth-for-gdm-htZpmD/database -seat seat0 vt1
root 6788 0.0 0.2 363148 4888 ? Sl 18:18 0:00 gdm-session-worker [pam/gdm-launch-environment]
root 6872 0.0 0.1 91628 2244 ? Ss 18:18 0:00 /usr/libexec/postfix/master -w
root 6970 0.0 0.0 53856 372 ? S 18:18 0:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
root 7132 0.0 0.3 430360 7328 ? Ssl 18:18 0:00 /usr/libexec/upowerd
root 8478 0.0 0.2 398564 3972 ? Ssl 18:18 0:00 /usr/libexec/boltd
root 8488 0.0 0.1 78560 3340 ? Ss 18:18 0:00 /usr/sbin/wpa_supplicant -u -f /var/log/wpa_supplicant.log -c /etc/wpa_supplicant/wpa_supplicant.conf -P /var/run/wpa_supplicant.pid
root 8500 0.0 0.2 410736 5568 ? Ssl 18:18 0:00 /usr/libexec/packagekitd
root 11756 0.0 0.0 0 0 ? S< 18:18 0:00 [kworker/3:1H]
root 13947 0.0 0.0 0 0 ? S< 18:18 0:00 [kworker/1:1H]
root 16139 0.0 0.0 0 0 ? S 18:18 0:00 [kworker/0:3]
root 16224 0.0 0.0 0 0 ? S 18:23 0:00 [kworker/0:0]
root 16383 0.0 0.0 0 0 ? S 18:40 0:00 [kworker/u256:2]
root 16586 0.0 0.0 0 0 ? S 19:00 0:00 [kworker/2:2]
root 16616 0.0 0.0 125384 1124 ? Ss 19:01 0:00 /usr/sbin/anacron -s
root 16707 0.0 0.0 0 0 ? S 19:10 0:00 [kworker/u256:1]
root 72210 0.0 0.3 160848 5616 ? Ds 19:49 0:00 sshd: root@pts/0
root 72216 0.0 0.1 116784 3484 pts/0 Ss 19:49 0:00 -bash
root 72260 0.0 0.0 0 0 ? S 19:49 0:00 [kworker/1:0]
root 72360 0.0 0.3 160848 5620 ? Ss 19:56 0:00 sshd: root@pts/1
root 72368 0.0 0.1 116652 3264 pts/1 Ss 19:56 0:00 -bash
root 72410 0.0 0.2 151888 5440 pts/1 S+ 19:56 0:00 vim test
root 72422 0.0 0.0 0 0 ? S 19:56 0:00 [kworker/1:2]
root 72472 0.4 0.0 0 0 ? S 20:00 0:00 [kworker/u256:0]
root 72629 0.0 0.0 107952 356 ? S 20:01 0:00 sleep 60
root 72637 0.0 0.0 0 0 ? S 20:01 0:00 [kworker/1:1]
root 72638 0.0 0.1 157444 1928 pts/0 R+ 20:02 0:00 ps -ux
查看PPID=1的进程
[root@localhost ~]# ps -ef | awk '$3==1'
root 3020 1 0 18:18 ? 00:00:00 /usr/lib/systemd/systemd-journald
root 3041 1 0 18:18 ? 00:00:00 /usr/sbin/lvmetad -f
root 3056 1 0 18:18 ? 00:00:00 /usr/lib/systemd/systemd-udevd
root 6035 1 0 18:18 ? 00:00:00 /sbin/auditd
root 6068 1 0 18:18 ? 00:00:00 /sbin/rngd -f
polkitd 6071 1 0 18:18 ? 00:00:00 /usr/lib/polkit-1/polkitd --no-debug
root 6072 1 0 18:18 ? 00:00:00 /usr/libexec/udisks2/udisksd
rpc 6073 1 0 18:18 ? 00:00:00 /sbin/rpcbind -w
root 6074 1 0 18:18 ? 00:00:00 /usr/sbin/irqbalance --foreground
root 6075 1 0 18:18 ? 00:00:00 /usr/bin/VGAuthService -s
root 6076 1 0 18:18 ? 00:00:00 /usr/sbin/smartd -n -q never
root 6077 1 0 18:18 ? 00:00:00 /usr/sbin/abrtd -d -s
root 6079 1 0 18:18 ? 00:00:00 /usr/bin/abrt-watch-log -F BUG: WARNING: at WARNING: CPU: INFO: possible recursive locking detected ernel BUG at list_del corruption list_add corruption do_IRQ: stack overflow: ear stack overflow (cur: eneral protection fault nable to handle kernel ouble fault: RTNL: assertion failed eek! page_mapcount(page) went negative! adness at NETDEV WATCHDOG ysctl table check failed : nobody cared IRQ handler type mismatch Kernel panic - not syncing: Machine Check Exception: Machine check events logged divide error: bounds: coprocessor segment overrun: invalid TSS: segment not present: invalid opcode: alignment check: stack segment: fpu exception: simd exception: iret exception: /var/log/messages -- /usr/bin/abrt-dump-oops -xtD
root 6080 1 0 18:18 ? 00:00:00 /usr/bin/abrt-watch-log -F Backtrace /var/log/Xorg.0.log -- /usr/bin/abrt-dump-xorg -xD
root 6081 1 0 18:18 ? 00:00:00 /usr/libexec/accounts-daemon
rtkit 6083 1 0 18:18 ? 00:00:00 /usr/libexec/rtkit-daemon
avahi 6087 1 0 18:18 ? 00:00:00 avahi-daemon: running [linux.local]
root 6088 1 0 18:18 ? 00:00:06 /usr/bin/vmtoolsd
root 6093 1 0 18:18 ? 00:00:00 /usr/sbin/ModemManager
root 6100 1 0 18:18 ? 00:00:00 /usr/sbin/alsactl -s -n 19 -c -E ALSA_CONFIG_PATH=/etc/alsa/alsactl.conf --initfile=/lib/alsa/init/00main rdaemon
libstor+ 6104 1 0 18:18 ? 00:00:00 /usr/bin/lsmd -d
dbus 6107 1 0 18:18 ? 00:00:00 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation
root 6122 1 0 18:18 ? 00:00:00 /usr/sbin/gssproxy -D
chrony 6130 1 0 18:18 ? 00:00:00 /usr/sbin/chronyd
root 6175 1 0 18:18 ? 00:00:00 /usr/lib/systemd/systemd-logind
root 6222 1 0 18:18 ? 00:00:00 /bin/bash /usr/sbin/ksmtuned
root 6460 1 0 18:18 ? 00:00:00 /usr/sbin/sshd -D
root 6463 1 0 18:18 ? 00:00:01 /usr/bin/python2 -Es /usr/sbin/tuned -l -P
root 6464 1 0 18:18 ? 00:00:00 /usr/sbin/cupsd -f
root 6466 1 0 18:18 ? 00:00:00 /usr/sbin/rsyslogd -n
root 6470 1 0 18:18 ? 00:00:00 /usr/sbin/libvirtd
root 6475 1 0 18:18 ? 00:00:00 /usr/sbin/gdm
root 6479 1 0 18:18 ? 00:00:00 /usr/sbin/crond -n
root 6480 1 0 18:18 ? 00:00:00 /usr/sbin/atd -f
root 6872 1 0 18:18 ? 00:00:00 /usr/libexec/postfix/master -w
gdm 6940 1 0 18:18 ? 00:00:00 dbus-launch --exit-with-session /usr/libexec/gnome-session-binary --autostart /usr/share/gdm/greeter/autostart
gdm 6958 1 0 18:18 ? 00:00:00 /usr/bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session
nobody 6969 1 0 18:18 ? 00:00:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
gdm 7009 1 0 18:18 ? 00:00:00 /usr/libexec/at-spi-bus-launcher
gdm 7023 1 0 18:18 ? 00:00:00 /usr/libexec/at-spi2-registryd --use-gnome-session
root 7132 1 0 18:18 ? 00:00:00 /usr/libexec/upowerd
gdm 7300 1 0 18:18 ? 00:00:00 /usr/bin/pulseaudio --start --log-target=syslog
gdm 8327 1 0 18:18 ? 00:00:00 /usr/libexec/ibus-x11 --kill-daemon
gdm 8332 1 0 18:18 ? 00:00:00 /usr/libexec/ibus-portal
gdm 8455 1 0 18:18 ? 00:00:00 /usr/libexec/xdg-permission-store
root 8478 1 0 18:18 ? 00:00:00 /usr/libexec/boltd
root 8488 1 0 18:18 ? 00:00:00 /usr/sbin/wpa_supplicant -u -f /var/log/wpa_supplicant.log -c /etc/wpa_supplicant/wpa_supplicant.conf -P /var/run/wpa_supplicant.pid
root 8500 1 0 18:18 ? 00:00:00 /usr/libexec/packagekitd
colord 8690 1 0 18:18 ? 00:00:00 /usr/libexec/colord
root 16616 1 0 19:01 ? 00:00:00 /usr/sbin/anacron -s