进程管理工具pstree,ps, top, pidof, pgrep, uptime
进程查看基本工具:pstree, ps, top, pidof, pgrep, uptime,htop
pstree查看进程树,linux系统上除init以外的所有子进程,都是由其父进程fork自身儿俩,遵循cow机制,进程展示位进程树 [root@localhost ~]# pstree
init─┬─NetworkManager─┬─dhclient │ └─{NetworkManager} ├─abrtd ├─acpid ├─atd ├─auditd───{auditd} ├─automount───4*[{automount}] ├─bluetoothd ├─crond ├─cupsd ├─dbus-daemon ├─hald─┬─hald-runner─┬─hald-addon-acpi │ │ ├─hald-addon-inpu │ │ └─hald-addon-rfki │ └─{hald} ├─master─┬─pickup │ └─qmgr ├─6*[mingetty] ├─modem-manager ├─rpc.statd ├─rpcbind ├─rsyslogd───3*[{rsyslogd}] ├─sshd───sshd───bash───pstree ├─udevd───2*[udevd] └─wpa_supplicant 显示进程pid [root@localhost ~]# pstree -p init(1)─┬─NetworkManager(1363)─┬─dhclient(1416) │ └─{NetworkManager}(1418) ├─abrtd(1759) ├─acpid(1451) ├─atd(1786) ├─auditd(1246)───{auditd}(1247) ├─automount(1564)─┬─{automount}(1565) │ ├─{automount}(1566) │ ├─{automount}(1569) │ └─{automount}(1572) ├─bluetoothd(1593) ├─crond(1772) ├─cupsd(1421) ├─dbus-daemon(1352) ├─hald(1461)─┬─hald-runner(1462)─┬─hald-addon-acpi(+ │ │ ├─hald-addon-inpu(+ │ │ └─hald-addon-rfki(+ │ └─{hald}(1463) ├─master(1733)─┬─pickup(12632) │ └─qmgr(1758) ├─mingetty(1812) ├─mingetty(1814) ├─mingetty(1816) ├─mingetty(1818) ├─mingetty(1820) ├─mingetty(1822) ├─modem-manager(1368) ├─rpc.statd(1384) ├─rpcbind(1321) ├─rsyslogd(1276)─┬─{rsyslogd}(1277) │ ├─{rsyslogd}(1279) │ └─{rsyslogd}(1280) ├─sshd(1626)───sshd(1823)───bash(1826)───pstree(128+ ├─udevd(406)─┬─udevd(882) │ └─udevd(883) └─wpa_supplicant(1422) [root@localhost ~]# process state linux运行中的内核的相关信息是通过/proc伪文件系统输出的:各进程都有一个以其PID命名的子目录,每个字目录中有许多存储了进程的相关状态信息
PS: 显示的是PS命令执行时,系统上当前进程状态信息的快照,所以,为静态
支持众多选项:分为两种风格, bsd风格 sysv风格
根据进程启动时是否通过终端上的接口交互式启动的,进程可分为两类
与终端相关的进程:a
与终端无关的进程:x
与终端相关的进程:a
[root@localhost ~]# ps a
PID TTY STAT TIME COMMAND
1812 tty1 Ss+ 0:00 /sbin/mingetty /dev/tty1
1814 tty2 Ss+ 0:00 /sbin/mingetty /dev/tty2
1816 tty3 Ss+ 0:00 /sbin/mingetty /dev/tty3
1818 tty4 Ss+ 0:00 /sbin/mingetty /dev/tty4
1820 tty5 Ss+ 0:00 /sbin/mingetty /dev/tty5
1822 tty6 Ss+ 0:00 /sbin/mingetty /dev/tty6
1826 pts/0 Ss 0:00 -bash
12873 pts/0 R+ 0:00 ps a
[root@localhost ~]#
与终端无关的进程:x
[root@localhost ~]# ps x
PID TTY STAT TIME COMMAND
1 ? Ss 0:01 /sbin/init
2 ? S 0:00 [kthreadd]
3 ? S 0:00 [migration/0]
4 ? S 0:00 [ksoftirqd/0]
5 ? S 0:00 [stopper/0]
6 ? S 0:00 [watchdog/0]
7 ? S 0:11 [events/0]
8 ? S 0:00 [cgroup]
9 ? S 0:00 [khelper]
10 ? S 0:00 [netns]
11 ? S 0:00 [async/mgr]
12 ? S 0:00 [pm]
13 ? S 0:00 [sync_supers]
14 ? S 0:00 [bdi-default]
15 ? S 0:00 [kintegrityd/0]
16 ? S 0:11 [kblockd/0]
17 ? S 0:00 [kacpid]
18 ? S 0:00 [kacpi_notify]
19 ? S 0:00 [kacpi_hotplug]
20 ? S 0:00 [ata_aux]
21 ? S 0:00 [ata_sff/0]
22 ? S 0:00 [ksuspend_usbd]
23 ? S 0:00 [khubd]
24 ? S 0:00 [kseriod]
25 ? S 0:00 [md/0]
26 ? S 0:00 [md_misc/0]
27 ? S 0:00 [linkwatch]
29 ? S 0:00 [khungtaskd]
30 ? S 0:00 [kswapd0]
31 ? SN 0:00 [ksmd]
32 ? S 0:00 [aio/0]
33 ? S 0:00 [crypto/0]
41 ? S 0:00 [kthrotld/0]
42 ? S 0:00 [pciehpd]
44 ? S 0:00 [kpsmoused]
45 ? S 0:00 [usbhid_resumer]
46 ? S 0:00 [deferwq]
78 ? S 0:00 [kdmremove]
79 ? S 0:00 [kstriped]
153 ? S 0:00 [scsi_eh_0]
154 ? S 0:00 [scsi_eh_1]
162 ? S 0:02 [mpt_poll_0]
163 ? S 0:00 [mpt/0]
164 ? S 0:00 [scsi_eh_2]
301 ? S 0:00 [kdmflush]
303 ? S 0:00 [kdmflush]
320 ? S 0:00 [jbd2/dm-0-8]
321 ? S 0:00 [ext4-dio-unwrit]
406 ? S
USER 属主 PID 进程id号 %CPU cpu %MEM 内存 VSZ 虚拟内存集,线性地址空间中占用的空间大小 RSS 常驻内存集,指不可以被交换至swap空间的数据占据空间大小; TTY STAT ||| 进程状态:r:running,运行状态 s:interruptible sleeping,可中断睡眠 d:uniterruptible sleeping,不可中断睡眠 t: stopped z: zombie
s: session leader +: 前台进程,占据着某终端 l: 多线程进程 <:高优先级进程 N:低优先级进程
START:启动时间 TIME :占据CPU累计时长 COMMAND :启动当前进程或线程的命令行程序,带[]为内核线程 常用组合选项2:-ef -e:显示所有进程 -f: 显示丰富格式信息 ppid:副进程id号
[root@localhost ~]# ps -e PID TTY TIME CMD 1 ? 00:00:01 init 2 ? 00:00:00 kthreadd 3 ? 00:00:00 migration/0 4 ? 00:00:00 ksoftirqd/0 5 ? 00:00:00 stopper/0 6 ? 00:00:00 watchdog/0 7 ? 00:00:12 events/0 8 ? 00:00:00 cgroup 9 ? 00:00:00 khelper 10 ? 00:00:00 netns 11 ? 00:00:00 async/mgr 12 ? 00:00:00 pm 13 ? 00:00:00 sync_supers 14 ? 00:00:00 bdi-default 15 ? 00:00:00 kintegrityd/0 16 ? 00:00:11 kblockd/0 17 ? 00:00:00 kacpid 18 ? 00:00:00 kacpi_notify 19 ? 00:00:00 kacpi_hotplug 20 ? 00:00:00 ata_aux 21 ? 00:00:00 ata_sff/0 22 ? 00:00:00 ksuspend_usbd 23 ? 00:00:00 khubd 24 ? 00:00:00 kseriod 25 ? 00:00:00 md/0 26 ? 00:00:00 md_misc/0 27 ? 00:00:00 linkwatch 29 ? 00:00:00 khungtaskd 30 ? 00:00:00 kswapd0 31 ? 00:00:00 ksmd 32 ? 00:00:00 aio/0 33 ? 00:00:00 crypto/0 41 ? 00:00:00 kthrotld/0 42 ? 00:00:00 pciehpd 44 ? 00:00:00 kpsmoused 45 ? 00:00:00 usbhid_resumer 46 ? 00:00:00 deferwq 78 ? 00:00:00 kdmremove 79 ? 00:00:00 kstriped 153 ? 00:00:00 scsi_eh_0 154 ? 00:00:00 scsi_eh_1 162 ? 00:00:02 mpt_poll_0 163 ? 00:00:00 mpt/0 164 ? 00:00:00 scsi_eh_2 301 ? 00:00:00 kdmflush 303 ? 00:00:00 kdmflush 320 ? 00:00:00 jbd2/dm-0-8 321 ? 00:00:00 ext4-dio-unwrit 406 ? 00:00:00 udevd 808 ? 00:00:00 bluetooth 815 ? 00:00:00 vmmemctl 882 ? 00:00:00 udevd 883 ? 00:00:00 udevd 895 ? 00:00:00 kdmflush 897 ? 00:00:00 kdmflush 954 ? 00:00:00 jbd2/sda1-8 955 ? 00:00:00 ext4-dio-unwrit 956 ? 00:00:00 jbd2/dm-2-8 957 ? 00:00:00 ext4-dio-unwrit 958 ? 00:00:00 jbd2/dm-3-8 959 ? 00:00:00 ext4-dio-unwrit 1004 ? 00:00:00 kauditd 1019 ? 00:00:00 flush-253:3 1246 ? 00:00:00 auditd 1276 ? 00:00:00 rsyslogd 1321 ? 00:00:02 rpcbind 1352 ? 00:00:00 dbus-daemon 1363 ? 00:00:00 NetworkManager 1368 ? 00:00:00 modem-manager 1384 ? 00:00:00 rpc.statd 1416 ? 00:00:00 dhclient 1421 ? 00:00:00 cupsd 1422 ? 00:00:00 wpa_supplicant 1451 ? 00:00:00 acpid 1461 ? 00:00:00 hald 1462 ? 00:00:00 hald-runner 1497 ? 00:00:00 hald-addon-rfki 1515 ? 00:00:00 hald-addon-inpu 1533 ? 00:00:00 hald-addon-acpi 1564 ? 00:00:00 automount 1593 ? 00:00:00 bluetoothd 1626 ? 00:00:00 sshd 1675 ? 00:00:00 krfcommd 1733 ? 00:00:00 master 1758 ? 00:00:00 qmgr 1759 ? 00:00:00 abrtd 1772 ? 00:00:00 crond 1786 ? 00:00:00 atd 1812 tty1 00:00:00 mingetty 1814 tty2 00:00:00 mingetty 1816 tty3 00:00:00 mingetty 1818 tty4 00:00:00 mingetty 1820 tty5 00:00:00 mingetty 1822 tty6 00:00:00 mingetty 1823 ? 00:00:00 sshd 1826 pts/0 00:00:00 bash 12894 ? 00:00:00 pickup 12926 pts/0 00:00:00 ps [root@localhost ~]#
[root@localhost ~]# ps -f UID PID PPID C STIME TTY TIME CMD root 1826 1823 0 08:19 pts/0 00:00:00 -bash root 12927 1826 0 11:50 pts/0 00:00:00 ps -f [root@localhost ~]# ps -ef UID PID PPID C STIME TTY TIME CMD root 1 0 0 08:18 ? 00:00:01 /sbin/init root 2 0 0 08:18 ? 00:00:00 [kthreadd] root 3 2 0 08:18 ? 00:00:00 [migration/] root 4 2 0 08:18 ? 00:00:00 [ksoftirqd/] root 5 2 0 08:18 ? 00:00:00 [stopper/0] root 6 2 0 08:18 ? 00:00:00 [watchdog/0] root 7 2 0 08:18 ? 00:00:12 [events/0] root 8 2 0 08:18 ? 00:00:00 [cgroup] root 9 2 0 08:18 ? 00:00:00 [khelper] root 10 2 0 08:18 ? 00:00:00 [netns] root 11 2 0 08:18 ? 00:00:00 [async/mgr] root 12 2 0 08:18 ? 00:00:00 [pm] root 13 2 0 08:18 ? 00:00:00 [sync_super] root 14 2 0 08:18 ? 00:00:00 [bdi-defaul] root 15 2 0 08:18 ? 00:00:00 [kintegrity] root 16 2 0 08:18 ? 00:00:11 [kblockd/0] root 17 2 0 08:18 ? 00:00:00 [kacpid] root 18 2 0 08:18 ? 00:00:00 [kacpi_noti] root 19 2 0 08:18 ? 00:00:00 [kacpi_hotp] root 20 2 0 08:18 ? 00:00:00 [ata_aux] root 21 2 0 08:18 ? 00:00:00 [ata_sff/0] root 22 2 0 08:18 ? 00:00:00 [ksuspend_u] root 23 2 0 08:18 ? 00:00:00 [khubd] root 24 2 0 08:18 ? 00:00:00 [kseriod] root 25 2 0 08:18 ? 00:00:00 [md/0] root 26 2 0 08:18 ? 00:00:00 [md_misc/0] root 27 2 0 08:18 ? 00:00:00 [linkwatch] root 29 2 0 08:18 ? 00:00:00 [khungtaskd] root 30 2 0 08:18 ? 00:00:00 [kswapd0] root 31 2 0 08:18 ? 00:00:00 [ksmd] root 32 2 0 08:18 ? 00:00:00 [aio/0] root 33 2 0 08:18 ? 00:00:00 [crypto/0] root 41 2 0 08:18 ? 00:00:00 [kthrotld/0] root 42 2 0 08:18 ? 00:00:00 [pciehpd] root 44 2 0 08:18 ? 00:00:00 [kpsmoused] root 45 2 0 08:18 ? 00:00:00 [usbhid_res] root 46 2 0 08:18 ? 00:00:00 [deferwq] root 78 2 0 08:18 ? 00:00:00 [kdmremove] root 79 2 0 08:18 ? 00:00:00 [kstriped] root 153 2 0 08:18 ? 00:00:00 [scsi_eh_0] root 154 2 0 08:18 ? 00:00:00 [scsi_eh_1] root 162 2 0 08:18 ? 00:00:02 [mpt_poll_0] root 163 2 0 08:18 ? 00:00:00 [mpt/0] root 164 2 0 08:18 ? 00:00:00 [scsi_eh_2] root 301 2 0 08:18 ? 00:00:00 [kdmflush] root 303 2 0 08:18 ? 00:00:00 [kdmflush] root 320 2 0 08:18 ? 00:00:00 [jbd2/dm-0-] root 321 2 0 08:18 ? 00:00:00 [ext4-dio-u] root 406 1 0 08:18 ? 00:00:00 /sbin/udevd root 808 2 0 08:18 ? 00:00:00 [bluetooth] root 815 2 0 08:18 ? 00:00:00 [vmmemctl] root 882 406 0 08:18 ? 00:00:00 /sbin/udevd root 883 406 0 08:18 ? 00:00:00 /sbin/udevd root 895 2 0 08:18 ? 00:00:00 [kdmflush] root 897 2 0 08:18 ? 00:00:00 [kdmflush] root 954 2 0 08:18 ? 00:00:00 [jbd2/sda1-] root 955 2 0 08:18 ? 00:00:00 [ext4-dio-u] root 956 2 0 08:18 ? 00:00:00 [jbd2/dm-2-] root 957 2 0 08:18 ? 00:00:00 [ext4-dio-u] root 958 2 0 08:18 ? 00:00:00 [jbd2/dm-3-] root 959 2 0 08:18 ? 00:00:00 [ext4-dio-u] root 1004 2 0 08:18 ? 00:00:00 [kauditd] root 1019 2 0 08:18 ? 00:00:00 [flush-253:] root 1246 1 0 08:18 ? 00:00:00 auditd root 1276 1 0 08:18 ? 00:00:00 /sbin/rsyslo rpc 1321 1 0 08:18 ? 00:00:02 rpcbind dbus 1352 1 0 08:18 ? 00:00:00 dbus-daemon root 1363 1 0 08:18 ? 00:00:00 NetworkManag root 1368 1 0 08:18 ? 00:00:00 /usr/sbin/mo rpcuser 1384 1 0 08:18 ? 00:00:00 rpc.statd root 1416 1363 0 08:18 ? 00:00:00 /sbin/dhclie root 1421 1 0 08:18 ? 00:00:00 cupsd -C /et root 1422 1 0 08:18 ? 00:00:00 /usr/sbin/wp root 1451 1 0 08:18 ? 00:00:00 /usr/sbin/ac 68 1461 1 0 08:18 ? 00:00:00 hald root 1462 1461 0 08:18 ? 00:00:00 hald-runner root 1497 1462 0 08:18 ? 00:00:00 /usr/libexec root 1515 1462 0 08:18 ? 00:00:00 hald-addon-i 68 1533 1462 0 08:18 ? 00:00:00 hald-addon-a root 1564 1 0 08:18 ? 00:00:00 automount -- root 1593 1 0 08:18 ? 00:00:00 /usr/sbin/bl root 1626 1 0 08:18 ? 00:00:00 /usr/sbin/ss root 1675 2 0 08:18 ? 00:00:00 [krfcommd] root 1733 1 0 08:18 ? 00:00:00 /usr/libexec postfix 1758 1733 0 08:18 ? 00:00:00 qmgr -l -t f root 1759 1 0 08:18 ? 00:00:00 /usr/sbin/ab root 1772 1 0 08:18 ? 00:00:00 crond root 1786 1 0 08:18 ? 00:00:00 /usr/sbin/at root 1812 1 0 08:18 tty1 00:00:00 /sbin/minget root 1814 1 0 08:18 tty2 00:00:00 /sbin/minget root 1816 1 0 08:18 tty3 00:00:00 /sbin/minget root 1818 1 0 08:18 tty4 00:00:00 /sbin/minget root 1820 1 0 08:18 tty5 00:00:00 /sbin/minget root 1822 1 0 08:18 tty6 00:00:00 /sbin/minget root 1823 1626 0 08:19 ? 00:00:00 sshd: root@p root 1826 1823 0 08:19 pts/0 00:00:00 -bash postfix 12894 1733 0 11:38 ? 00:00:00 pickup -l -t root 12929 1826 0 11:50 pts/0 00:00:00 ps -ef [root@localhost ~]# 常用组合选项3:-eFH -F:显示额外信息 -H:以层级形式显示进程间关系
自定义查看需要显示的信息:o,通常使用axo 示例: ps axo pid ,command,psr,pri,ni psr:当前进程运行的cpu编号 pri:当前进程的优先级 ni:当前进程的nice值 -20,19 [root@localhost ~]# ps -eFH UID PID PPID C SZ RSS PSR STIME TTY TIME CMD root 2 0 0 0 0 0 08:18 ? 00:00:00 [kthreadd] root 3 2 0 0 0 0 08:18 ? 00:00:00 [migration/0] root 4 2 0 0 0 0 08:18 ? 00:00:00 [ksoftirqd/0] root 5 2 0 0 0 0 08:18 ? 00:00:00 [stopper/0] root 6 2 0 0 0 0 08:18 ? 00:00:00 [watchdog/0] root 7 2 0 0 0 0 08:18 ? 00:00:12 [events/0] root 8 2 0 0 0 0 08:18 ? 00:00:00 [cgroup] root 9 2 0 0 0 0 08:18 ? 00:00:00 [khelper] root 10 2 0 0 0 0 08:18 ? 00:00:00 [netns] root 11 2 0 0 0 0 08:18 ? 00:00:00 [async/mgr] root 12 2 0 0 0 0 08:18 ? 00:00:00 [pm] root 13 2 0 0 0 0 08:18 ? 00:00:00 [sync_supers] root 14 2 0 0 0 0 08:18 ? 00:00:00 [bdi-default] root 15 2 0 0 0 0 08:18 ? 00:00:00 [kintegrityd/0] root 16 2 0 0 0 0 08:18 ? 00:00:11 [kblockd/0] root 17 2 0 0 0 0 08:18 ? 00:00:00 [kacpid] root 18 2 0 0 0 0 08:18 ? 00:00:00 [kacpi_notify] root 19 2 0 0 0 0 08:18 ? 00:00:00 [kacpi_hotplug] root 20 2 0 0 0 0 08:18 ? 00:00:00 [ata_aux] root 21 2 0 0 0 0 08:18 ? 00:00:00 [ata_sff/0] root 22 2 0 0 0 0 08:18 ? 00:00:00 [ksuspend_usbd] root 23 2 0 0 0 0 08:18 ? 00:00:00 [khubd] root 24 2 0 0 0 0 08:18 ? 00:00:00 [kseriod] root 25 2 0 0 0 0 08:18 ? 00:00:00 [md/0] root 26 2 0 0 0 0 08:18 ? 00:00:00 [md_misc/0] root 27 2 0 0 0 0 08:18 ? 00:00:00 [linkwatch] root 29 2 0 0 0 0 08:18 ? 00:00:00 [khungtaskd] root 30 2 0 0 0 0 08:18 ? 00:00:00 [kswapd0] root 31 2 0 0 0 0 08:18 ? 00:00:00 [ksmd] root 32 2 0 0 0 0 08:18 ? 00:00:00 [aio/0] root 33 2 0 0 0 0 08:18 ? 00:00:00 [crypto/0] root 41 2 0 0 0 0 08:18 ? 00:00:00 [kthrotld/0] root 42 2 0 0 0 0 08:18 ? 00:00:00 [pciehpd] root 44 2 0 0 0 0 08:18 ? 00:00:00 [kpsmoused] root 45 2 0 0 0 0 08:18 ? 00:00:00 [usbhid_resumer] root 46 2 0 0 0 0 08:18 ? 00:00:00 [deferwq] root 78 2 0 0 0 0 08:18 ? 00:00:00 [kdmremove] root 79 2 0 0 0 0 08:18 ? 00:00:00 [kstriped] root 153 2 0 0 0 0 08:18 ? 00:00:00 [scsi_eh_0] root 154 2 0 0 0 0 08:18 ? 00:00:00 [scsi_eh_1] root 162 2 0 0 0 0 08:18 ? 00:00:02 [mpt_poll_0] root 163 2 0 0 0 0 08:18 ? 00:00:00 [mpt/0] root 164 2 0 0 0 0 08:18 ? 00:00:00 [scsi_eh_2] root 301 2 0 0 0 0 08:18 ? 00:00:00 [kdmflush] root 303 2 0 0 0 0 08:18 ? 00:00:00 [kdmflush] root 320 2 0 0 0 0 08:18 ? 00:00:00 [jbd2/dm-0-8] root 321 2 0 0 0 0 08:18 ? 00:00:00 [ext4-dio-unwrit] root 808 2 0 0 0 0 08:18 ? 00:00:00 [bluetooth] root 815 2 0 0 0 0 08:18 ? 00:00:00 [vmmemctl] root 895 2 0 0 0 0 08:18 ? 00:00:00 [kdmflush] root 897 2 0 0 0 0 08:18 ? 00:00:00 [kdmflush] root 954 2 0 0 0 0 08:18 ? 00:00:00 [jbd2/sda1-8] root 955 2 0 0 0 0 08:18 ? 00:00:00 [ext4-dio-unwrit] root 956 2 0 0 0 0 08:18 ? 00:00:00 [jbd2/dm-2-8] root 957 2 0 0 0 0 08:18 ? 00:00:00 [ext4-dio-unwrit] root 958 2 0 0 0 0 08:18 ? 00:00:00 [jbd2/dm-3-8] root 959 2 0 0 0 0 08:18 ? 00:00:00 [ext4-dio-unwrit] root 1004 2 0 0 0 0 08:18 ? 00:00:00 [kauditd] root 1019 2 0 0 0 0 08:18 ? 00:00:00 [flush-253:3] root 1675 2 0 0 0 0 08:18 ? 00:00:00 [krfcommd] root 1 0 0 4839 1540 0 08:18 ? 00:00:01 /sbin/init root 406 1 0 2782 1244 0 08:18 ? 00:00:00 /sbin/udevd -d root 882 406 0 2782 1260 0 08:18 ? 00:00:00 /sbin/udevd -d root 883 406 0 2782 1260 0 08:18 ? 00:00:00 /sbin/udevd -d root 1246 1 0 6899 824 0 08:18 ? 00:00:00 auditd root 1276 1 0 62274 1652 0 08:18 ? 00:00:00 /sbin/rsyslogd -i /var/run/syslogd.pid -c 5 rpc 1321 1 0 4744 900 0 08:18 ? 00:00:02 rpcbind dbus 1352 1 0 5395 1172 0 08:18 ? 00:00:00 dbus-daemon --system root 1363 1 0 43270 4684 0 08:18 ? 00:00:00 NetworkManager --pid-file=/var/run/NetworkManager/NetworkManager.pid root 1416 1363 0 2280 1568 0 08:18 ? 00:00:00 /sbin/dhclient -d -4 -sf /usr/libexec/nm-dhcp-client.action -pf /var/run/dhclient root 1368 1 0 14534 2456 0 08:18 ? 00:00:00 /usr/sbin/modem-manager rpcuser 1384 1 0 5837 1372 0 08:18 ? 00:00:00 rpc.statd root 1421 1 0 47352 3780 0 08:18 ? 00:00:00 cupsd -C /etc/cups/cupsd.conf root 1422 1 0 11247 672 0 08:18 ? 00:00:00 /usr/sbin/wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf -B -u -f /var/l root 1451 1 0 1020 652 0 08:18 ? 00:00:00 /usr/sbin/acpid 68 1461 1 0 9796 5488 0 08:18 ? 00:00:00 hald root 1462 1461 0 5100 1168 0 08:18 ? 00:00:00 hald-runner root 1497 1462 0 5628 1076 0 08:18 ? 00:00:00 /usr/libexec/hald-addon-rfkill-killswitch root 1515 1462 0 5630 1080 0 08:18 ? 00:00:00 hald-addon-input: Listening on /dev/input/event2 /dev/input/event0 68 1533 1462 0 4502 1028 0 08:18 ? 00:00:00 hald-addon-acpi: listening on acpid socket /var/run/acpid.socket root 1564 1 0 96533 1912 0 08:18 ? 00:00:00 automount --pid-file /var/run/autofs.pid root 1593 1 0 6197 1852 0 08:18 ? 00:00:00 /usr/sbin/bluetoothd --udev root 1626 1 0 16672 1272 0 08:18 ? 00:00:00 /usr/sbin/sshd root 1823 1626 0 25112 4464 0 08:19 ? 00:00:00 sshd: root@pts/0 root 1826 1823 0 27085 1828 0 08:19 pts/0 00:00:00 -bash root 12934 1826 1 27587 1104 0 11:52 pts/0 00:00:00 ps -eFH root 1733 1 0 20332 3856 0 08:18 ? 00:00:00 /usr/libexec/postfix/master postfix 1758 1733 0 20398 3868 0 08:18 ? 00:00:00 qmgr -l -t fifo -u postfix 12894 1733 0 20352 3828 0 11:38 ? 00:00:00 pickup -l -t fifo -u root 1759 1 0 28661 1124 0 08:18 ? 00:00:00 /usr/sbin/abrtd root 1772 1 0 29333 1272 0 08:18 ? 00:00:00 crond root 1786 1 0 5394 512 0 08:18 ? 00:00:00 /usr/sbin/atd root 1812 1 0 1016 536 0 08:18 tty1 00:00:00 /sbin/mingetty /dev/tty1 root 1814 1 0 1016 544 0 08:18 tty2 00:00:00 /sbin/mingetty /dev/tty2 root 1816 1 0 1016 540 0 08:18 tty3 00:00:00 /sbin/mingetty /dev/tty3 root 1818 1 0 1016 540 0 08:18 tty4 00:00:00 /sbin/mingetty /dev/tty4 root 1820 1 0 1016 544 0 08:18 tty5 00:00:00 /sbin/mingetty /dev/tty5 root 1822 1 0 1016 544 0 08:18 tty6 00:00:00 /sbin/mingetty /dev/tty6 [root@localhost ~]# pgrep: -u 用户 -g 组 -l id号和进程名 [root@localhost ~]# pgrep "bash" 1826 [root@localhost ~]# [root@localhost ~]# pgrep -u root 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 29 30 31 32 [root@localhost ~]# pgrep -l -u root 1 init 2 kthreadd 3 migration/0 4 ksoftirqd/0 5 stopper/0 6 watchdog/0 7 events/0 8 cgroup 9 khelper 10 netns 11 async/mgr 12 pm 13 sync_supers 14 bdi-default 15 kintegrityd/0 16 kblockd/0 17 kacpid 18 kacpi_notify 19 kacpi_hotplug 20 ata_aux 21 ata_sff/0 22 ksuspend_usbd 23 khubd 24 kseriod 25 md/0 26 md_misc/0 27 linkwatch 29 khungtaskd 30 kswapd0 31 ksmd 32 aio/0 33 crypto/0 41 kthrotld/0 42 pciehpd 44 kpsmoused 45 usbhid_resumer 46 deferwq 78 kdmremove 79 kstriped 153 scsi_eh_0 154 scsi_eh_1 162 mpt_poll_0 163 mpt/0 164 scsi_eh_2 301 kdmflush 303 kdmflush 320 jbd2/dm-0-8 321 ext4-dio-unwrit 406 udevd 808 bluetooth 815 vmmemctl 882 udevd 883 udevd 895 kdmflush 897 kdmflush 954 jbd2/sda1-8 955 ext4-dio-unwrit 956 jbd2/dm-2-8 957 ext4-dio-unwrit 958 jbd2/dm-3-8 959 ext4-dio-unwrit 1004 kauditd 1019 flush-253:3 1246 auditd 1276 rsyslogd 1363 NetworkManager 1368 modem-manager 1416 dhclient 1421 cupsd 1422 wpa_supplicant 1451 acpid 1462 hald-runner 1497 hald-addon-rfki 1515 hald-addon-inpu 1564 automount 1593 bluetoothd 1626 sshd 1675 krfcommd 1733 master 1759 abrtd 1772 crond 1786 atd 1812 mingetty 1814 mingetty 1816 mingetty 1818 mingetty 1820 mingetty 1822 mingetty 1823 sshd 1826 bash 12950 flush-253:2 [root@localhost ~]# pi pidof
pidof 命令行程序 [root@localhost ~]# pidof /bin/bash 1826 [root@localhost ~]# top命令: 有许多交互式的子命令: p:以占据的cpu百分比大小排序; M:以占据memory空间大小排序 T:cpu累计占用时间排序
l:是否显示系统负载行 队列长度的合理时间:cpu颗数*0.7 t:是否显示进程摘要信息及cpu负载状态
[root@localhost ~]# top top - 12:04:14 up 3:46, 1 user, load average: 0.02, 0.01, 0.00 Tasks: 99 total, 1 running, 98 sleeping, 0 stopped, 0 zombie Cpu(s): 0.3%us, 0.3%sy, 0.0%ni, 99.3%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 494164k total, 430180k used, 63984k free, 28432k buffers Swap: 2097148k total, 0k used, 2097148k free, 315536k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1 root 20 0 19356 1540 1224 S 0.0 0.3 0:01.22 init 2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd 3 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0 4 root 20 0 0 0 0 S 0.0 0.0 0:00.03 ksoftirqd/0 5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 stopper/0 6 root RT 0 0 0 0 S 0.0 0.0 0:00.69 watchdog/0 7 root 20 0 0 0 0 S 0.0 0.0 0:13.15 events/0 8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cgroup 9 root 20 0 0 0 0 S 0.0 0.0 0:00.00 khelper 10 root 20 0 0 0 0 S 0.0 0.0 0:00.00 netns 11 root 20 0 0 0 0 S 0.0 0.0 0:00.00 async/mgr 12 root 20 0 0 0 0 S 0.0 0.0 0:00.00 pm 13 root 20 0 0 0 0 S 0.0 0.0 0:00.54 sync_supers 14 root 20 0 0 0 0 S 0.0 0.0 0:00.10 bdi-default 15 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kintegrityd/0 16 root 20 0 0 0 0 S 0.0 0.0 0:12.00 kblockd/0 17 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kacpid 18 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kacpi_notify 19 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kacpi_hotplug 20 root 20 0 0 0 0 S 0.0 0.0 0:00.00 ata_aux 21 root 20 0 0 0 0 S 0.0 0.0 0:00.00 ata_sff/0 22 root 20 0 0 0 0 S 0.0 0.0 0:00.00 ksuspend_usbd
top--译
[root@localhost ~]# top top - 12:04:14 当前系统时间 up 3:46, 运行时长 1 user, 当前系统登录的用户个数 load average: 0.02, 0.01, 0.00 平均负载,当前系统上cpu队列等待长度 0.02, 过去一份钟 0.01, 过去5分钟 队列长度的合理区间:cpu颗数*0.7
Tasks: 99 total, 1 running, 98 sleeping, 0 stopped, 0 zombie tasks:一共 99 total:99个停止 Cpu(s): 0.3%us, 0.3%sy, 0.0%ni, 99.3%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
us:user space sy:system(kernel space) ni:nice id:idle wa:wai io hi:hardware interrupt si:software interrupt st:stolen,被虚拟化”偷走“的百分比 Mem: 494164k total, 430180k used, 63984k free, 28432k buffers Swap: 2097148k total, 0k used, 2097148k free, 315536k cached
内存占用信息:m命令开启关闭
m: 显示关闭内存信息 1,平均或单独显示cpu的负载状态 s:修改刷新时间间隔 k: 终止指定进程
top命令选项: [root@localhost ~]# top -b b:batch,批次显示
[root@localhost ~]# top -b -n 2 -n 数字:显示的批次数
[root@localhost ~]# top -d 2 -d:指明延迟时长
和ps介绍一致! PID USER PR 优先级 NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND uptime:显示当前系统时间,运行时长,登录用户数及系统平均负载 [root@localhost ~]# uptime 12:11:56 up 3:53, 1 user, load average: 0.00, 0.00, 0.00 [root@localhost ~]#