linux进程的高级管理,Linux进程查看,管理工具

浅谈linux下进程查看,管理工具

1.pstree 显示进程树。

显示各个进程之间的关系[root@test ~]# pstree

init─┬─abrtd

├─acpid

├─atd

├─console-kit-dae───63*[{console-kit-da}]

├─crond

├─cupsd

├─dbus-daemon

├─dhclient

├─fcoemon

├─hald─┬─hald-runner─┬─hald-addon-acpi

│      │             └─hald-addon-inpu

│      └─{hald}

├─lldpad

├─login───bash

├─master─┬─pickup

│        └─qmgr

├─5*[mingetty]

├─rpcbind

├─rsyslogd───3*[{rsyslogd}]

├─sshd─┬─sshd───2*[bash]

│      └─sshd───bash───pstree

└─udevd───2*[udevd]

2.ps 进程状态查看工具

ps aux

a 与终端相关的进程

x 与终端无关的进程

u 显示以用户为中心组织进程状态信息[root@test ~]# ps aux

USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND

VSZ 虚拟内存集

RSS 常住内存集不能被交换

STAT 进程状态

R running

S 可中断睡眠

D 不可中断睡眠

T 停止态

Z 僵尸态

+ 前台进程

l 多线程进程

N 低优先级进程

s session leader

root       1584  0.0  0.1 251200  1692 ?        Sl   18:37   0:00 /sbin/rsyslogd -i /var/run/syslogd.pid -c 5

root       1614  0.0  0.0  18308   724 ?        Ss   18:37   0:06 irqbalance --pid=/var/run/irqbalance.pid

rpc        1630  0.0  0.0  18976   904 ?        Ss   18:37   0:00 rpcbind

dbus       1662  0.0  0.1  21712  1248 ?        Ss   18:38   0:02 dbus-daemon --system

root       1673  0.0  0.6 101196  6424 ?        Ssl  18:38   0:01 NetworkManager --pid-file=/var/run/NetworkManager/NetworkManager.pid

root       1677  0.0  0.2  58136  2432 ?        S    18:38   0:00 /usr/sbin/modem-manager

rpcuser    1694  0.0  0.1  23348  1372 ?        Ss   18:38   0:00 rpc.statd

root       1726  0.0  0.3 189408  3780 ?        Ss   18:38   0:00 cupsd -C /etc/cups/cupsd.conf

root       1753  0.0  0.0  44988   688 ?        Ss   18:38   0:00 /usr/sbin/wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf -B -u -f /var/log/w

root       1791  0.0  0.0   4080   652 ?        Ss   18:38   0:00 /usr/sbin/acpid

68         1801  0.0  0.5  39352  5584 ?        Ssl  18:38   0:00 hald

root       1802  0.0  0.1  20400  1180 ?        S    18:38   0:00 hald-runner

root       1847  0.0  0.1  22520  1088 ?        S    18:38   0:00 hald-addon-input: Listening on /dev/input/event2 /dev/input/event0

68         1854  0.0  0.1  18008  1028 ?        S    18:38   0:00 hald-addon-acpi: listening on acpid socket /var/run/acpid.socket

root       1875  0.0  0.1 386140  1924 ?        Ssl  18:38   0:00 automount --pid-file /var/run/autofs.pid

root       1904  0.0  0.1  66688  1272 ?        Ss   18:38   0:00 /usr/sbin/sshd

root       2018  0.0  0.3  81328  3848 ?        Ss   18:38   0:00 /usr/libexec/postfix/master

postfix    2039  0.0  0.3  81592  3868 ?        S    18:38   0:00 qmgr -l -t fifo -u

root       2045  0.0  0.1 114644  1124 ?        Ss   18:38   0:00 /usr/sbin/abrtd

root       2057  0.0  0.1 117336  1272 ?        Ss   18:38   0:00 crond

root       2071  0.0  0.0  21576   516 ?        Ss   18:38   0:00 /usr/sbin/atd

root       2097  0.0  0.2  79520  2980 ?        Ss   18:38   0:00 login -- root

root       2099  0.0  0.0   4064   540 tty2     Ss+  18:38   0:00 /sbin/mingetty /dev/tty2

root       2101  0.0  0.0   4064   540 tty3     Ss+  18:38   0:00 /sbin/mingetty /dev/tty3

root       2103  0.0  0.0   4064   540 tty4     Ss+  18:38   0:00 /sbin/mingetty /dev/tty4

root       2105  0.0  0.0   4064   540 tty5     Ss+  18:38   0:00 /sbin/mingetty /dev/tty5

root       2107  0.0  0.0   4064   540 tty6     Ss+  18:38   0:00 /sbin/mingetty /dev/tty6

root       2113  0.0  0.3 2085036 3428 ?        Sl   18:38   0:00 /usr/sbin/console-kit-daemon --no-daemon

root       2180  0.0  0.1 108336  1792 tty1     Ss+  18:38   0:00 -bash

root       2859  0.0  0.4  52772  4440 ?        S    19:47   0:01 /usr/libexec/polkit-1/polkitd

root       3314  0.0  0.0  10824   880 ?        S

root       3315  0.0  0.0  10824   880 ?        S

postfix    3597  0.0  0.3  81408  3820 ?        S    21:58   0:00 pickup -l -t fifo -u

named      5494  0.1  1.5 385320 15576 ?        Ssl  23:04   0:02 /usr/sbin/named -u named

root       5511  0.0  0.4 100448  4424 ?        Ss   23:04   0:00 sshd: root@pts/0

root       5515  0.0  0.1 108340  1772 pts/0    Ss+  23:04   0:00 -bash

root       5983  0.2  0.1   9120  1564 ?        S    23:19   0:00 /sbin/dhclient -d -4 -sf /usr/libexec/nm-dhcp-client.action -pf /var/run/dhclient-eth0.

root       6148  0.4  0.4 100448  4440 ?        Rs   23:19   0:00 sshd: root@pts/1

root       6151  0.1  0.1 108340  1772 pts/1    Ss   23:19   0:00 -bash

root       6181  2.0  0.1 110236  1124 pts/1    R+   23:21   0:00 ps aux

ps -ef

e 显示所有进程

f 显示完整格式进程[root@test ~]# ps -ef

rpc        1630      1  0 18:37 ?        00:00:00 rpcbind

dbus       1662      1  0 18:38 ?        00:00:02 dbus-daemon --system

root       1673      1  0 18:38 ?        00:00:01 NetworkManager --pid-file=/var/run/NetworkManager/NetworkManager.pid

root       1677      1  0 18:38 ?        00:00:00 /usr/sbin/modem-manager

rpcuser    1694      1  0 18:38 ?        00:00:00 rpc.statd

root       1726      1  0 18:38 ?        00:00:00 cupsd -C /etc/cups/cupsd.conf

root       1753      1  0 18:38 ?        00:00:00 /usr/sbin/wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf -B -u -f /var/log/wpa_supplicant.lo

root       1791      1  0 18:38 ?        00:00:00 /usr/sbin/acpid

68         1801      1  0 18:38 ?        00:00:00 hald

root       1802   1801  0 18:38 ?        00:00:00 hald-runner

root       1847   1802  0 18:38 ?        00:00:00 hald-addon-input: Listening on /dev/input/event2 /dev/input/event0

68         1854   1802  0 18:38 ?        00:00:00 hald-addon-acpi: listening on acpid socket /var/run/acpid.socket

root       1875      1  0 18:38 ?        00:00:00 automount --pid-file /var/run/autofs.pid

root       1904      1  0 18:38 ?        00:00:00 /usr/sbin/sshd

root       2018      1  0 18:38 ?        00:00:00 /usr/libexec/postfix/master

postfix    2039   2018  0 18:38 ?        00:00:00 qmgr -l -t fifo -u

root       2045      1  0 18:38 ?        00:00:00 /usr/sbin/abrtd

root       2057      1  0 18:38 ?        00:00:00 crond

root       2071      1  0 18:38 ?        00:00:00 /usr/sbin/atd

root       2097      1  0 18:38 ?        00:00:00 login -- root

root       2099      1  0 18:38 tty2     00:00:00 /sbin/mingetty /dev/tty2

root       2101      1  0 18:38 tty3     00:00:00 /sbin/mingetty /dev/tty3

root       2103      1  0 18:38 tty4     00:00:00 /sbin/mingetty /dev/tty4

root       2105      1  0 18:38 tty5     00:00:00 /sbin/mingetty /dev/tty5

root       2107      1  0 18:38 tty6     00:00:00 /sbin/mingetty /dev/tty6

root       2113      1  0 18:38 ?        00:00:00 /usr/sbin/console-kit-daemon --no-daemon

root       2180   2097  0 18:38 tty1     00:00:00 -bash

root       2859      1  0 19:47 ?        00:00:01 /usr/libexec/polkit-1/polkitd

root       3314    497  0 19:51 ?        00:00:00 /sbin/udevd -d

root       3315    497  0 19:51 ?        00:00:00 /sbin/udevd -d

postfix    3597   2018  0 21:58 ?        00:00:00 pickup -l -t fifo -u

named      5494      1  0 23:04 ?        00:00:02 /usr/sbin/named -u named

root       5511   1904  0 23:04 ?        00:00:00 sshd: root@pts/0

root       5515   5511  0 23:04 pts/0    00:00:00 -bash

root       5983   1673  0 23:19 ?        00:00:00 /sbin/dhclient -d -4 -sf /usr/libexec/nm-dhcp-client.action -pf /var/run/dhclient-eth0.pid -lf /var/lib

root       6148   1904  0 23:19 ?        00:00:00 sshd: root@pts/1

root       6151   6148  0 23:19 pts/1    00:00:00 -bash

root       6178   6151 35 23:20 pts/1    00:00:00 ps -ef

[root@test ~]#

注意:Linux系统各进程的相关信息均保存在/pro/PID目录下的各文件中

3.top

排序 按P:以占据CPU百分比

按M:以占据内存百分比

按T:累计占据CPU时长[root@test ~]# top

top - 23:20:16 up  4:42,  3 users,  load average: 0.06, 0.03, 0.00

Tasks: 165 total,   1 running, 164 sleeping,   0 stopped,   0 zombie

Cpu(s):  0.0%us,  0.1%sy,  0.0%ni, 99.9%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st

Mem:   1004352k total,   409576k used,   594776k free,    53076k buffers

Swap:  2097148k total,        0k used,  2097148k free,   197528k cached

PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND

6177 root      20   0 15036 1264  928 R  0.7  0.1   0:00.07 top

1 root      20   0 19364 1536 1224 S  0.0  0.2   0:01.48 init

2 root      20   0     0    0    0 S  0.0  0.0   0:00.01 kthreadd

3 root      RT   0     0    0    0 S  0.0  0.0   0:00.02 migration/0

4 root      20   0     0    0    0 S  0.0  0.0   0:00.02 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.04 watchdog/0

7 root      RT   0     0    0    0 S  0.0  0.0   0:00.59 migration/1

8 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 stopper/1

9 root      20   0     0    0    0 S  0.0  0.0   0:00.07 ksoftirqd/1

10 root      RT   0     0    0    0 S  0.0  0.0   0:00.04 watchdog/1

11 root      RT   0     0    0    0 S  0.0  0.0   0:00.05 migration/2

12 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 stopper/2

13 root      20   0     0    0    0 S  0.0  0.0   0:00.03 ksoftirqd/2

14 root      RT   0     0    0    0 S  0.0  0.0   0:00.03 watchdog/2

15 root      RT   0     0    0    0 S  0.0  0.0   0:00.04 migration/3

16 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 stopper/3

17 root      20   0     0    0    0 S  0.0  0.0   0:00.02 ksoftirqd/3

18 root      RT   0     0    0    0 S  0.0  0.0   0:00.03 watchdog/3

19 root      20   0     0    0    0 S  0.0  0.0   0:01.20 events/0

20 root      20   0     0    0    0 S  0.0  0.0   0:02.16 events/1

21 root      20   0     0    0    0 S  0.0  0.0   0:16.68 events/2

22 root      20   0     0    0    0 S  0.0  0.0   0:12.25 events/3

23 root      20   0     0    0    0 S  0.0  0.0   0:00.00 cgroup

24 root      20   0     0    0    0 S  0.0  0.0   0:00.00 khelper

25 root      20   0     0    0    0 S  0.0  0.0   0:00.00 netns

26 root      20   0     0    0    0 S  0.0  0.0   0:00.00 async/mgr

27 root      20   0     0    0    0 S  0.0  0.0   0:00.00 pm

28 root      20   0     0    0    0 S  0.0  0.0   0:00.14 sync_supers

29 root      20   0     0    0    0 S  0.0  0.0   0:00.14 bdi-default

30 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kintegrityd/0

31 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kintegrityd/1

32 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kintegrityd/2

4.vmstat[root@test ~]# vmstat 2 10   #每2秒刷新一次,一共刷新10次

procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----

r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st

r:等待运行进程的个数

b:处于不可中断睡眠态的进程个数(被阻塞的队列长度)

si 数据进入swap中的数据速率kb/s

so 数据离开swap中的数据速率kb/s

bi 从块设备读入数据速率

bo 从块设备输出数据速率

in 中断速率

cs 每秒上下文切换次数

us 用户空间占据比例

sy 内核空间占据的比例

id 空闲

wa 等待io完成

1  0      0 1486576  80572 344080    0    0     1     1    6    5  0  0 100  0  0

0  0      0 1486568  80572 344080    0    0     0     0   34   18  0  0 100  0  0

0  0      0 1486568  80580 344080    0    0     0     6   28   27  0  0 100  0  0

0  0      0 1486568  80580 344080    0    0     0     0   22   19  0  0 100  0  0

0  0      0 1486568  80580 344080    0    0     0     2   29   28  0  0 100  0  0

0  0      0 1486568  80580 344080    0    0     0     0   23   14  0  0 100  0  0

0  0      0 1486568  80580 344080    0    0     0     2   27   26  0  0 100  0  0

0  0      0 1486568  80580 344080    0    0     0     0   22   16  0  0 100  0  0

0  0      0 1486568  80580 344080    0    0     0     0   26   24  0  0 100  0  0

0  0      0 1486568  80580 344080    0    0     0     0   24   18  0  0 100  0  0

5.glances

-h 查看帮助

-b 以byte为单位显示

-d 关闭磁盘I/O模块

-f /path/to/file 设定输入文件位置

-o {html|csv} 输出格式

-m 禁用mount模块

-n 禁用网络模块

C/S模式下运行glances

服务器模式 glances -s -B IPADDR 监听在本机的地址

客户端模式 glances -c IPADDR 服务器的地址

757627859f6d13d1c2c12dd93fd03a26.png   6.dstat

-c: 显示cpu相关信息;

-C #,#,..|total 显示具体某个核心信息

-d: 只显示disk相关信息;

-D /device|total 显示固定设备的I/O或者所有

-g:显示page相关统计数据;

-m: 显示memory相关统计数据;

-n: 显示network相关统计数据;

-p: 显示process相关统计数据;

-r: 显示io请求相关的统计数据;

-s: 显示swapped相关的统计数据;

--top-cpu:显示最占用CPU的进程;

--top-io: 显示最占用io的进程;

--top-mem: 显示最占用内存的进程;

--top-lantency: 显示延迟最大的进程;[root@test-3 ~]# dstat

----total-cpu-usage---- -dsk/total- -net/total- ---paging-- ---system--

usr sys idl wai hiq siq| read  writ| recv  send|  in   out | int   csw

0   0 100   0   0   0|  13k 6108B|   0     0 |   0     0 |  29    26

0   0 100   0   0   0|   0     0 |  60B  826B|   0     0 |  21    17

0   0  99   0   0   0|   0   108k|  60B  346B|   0     0 |  31    28

0   0 100   0   0   0|   0     0 |  60B  346B|   0     0 |  29    24

0   0 100   0   0   0|   0     0 |  60B  346B|   0     0 |  39    40

0   0 100   0   0   0|   0     0 | 150B  400B|   0     0 |  21    21

0   0 100   0   0   0|   0     0 |  60B  346B|   0     0 |  22    19

0   0 100   0   0   0|   0     0 |  60B  346B|   0     0 |  24    22

0   0 100   0   0   0|   0     0 |  60B  346B|   0     0 |  21    19

0   0 100   0   0   0|   0     0 |  60B  346B|   0     0 |  18    19

0   0 100   0   0   0|   0     0 | 120B  346B|   0     0 |  26    26

0   0 100   0   0   0|   0     0 |  60B  346B|   0     0 |  18    17

0   0 100   0   0   0|   0     0 |  60B  346B|   0     0 |  25    21

0   0 100   0   0   0|   0     0 |  60B  346B|   0     0 |  26    22

0   0 100   0   0   0|   0     0 |  60B  346B|   0     0 |  25    22

0   0 100   0   0   0|   0     0 |  60B  346B|   0     0 |  21    20

0   0 100   0   0   0|   0     0 | 120B  388B|   0     0 |  29    28

0   0 100   0   0   0|   0     0 |  60B  346B|   0     0 |  17    21

0   0 100   0   0   0|   0     0 |  60B  346B|   0     0 |  24    21

0   0 100   0   0   0|   0     0 |  60B  346B|   0     0 |  19    19

0   0 100   0   0   0|   0     0 |  60B  346B|   0     0 |  20    18

0   0 100   0   0   0|   0     0 |  60B  346B|   0     0 |  15    17

0   0 100   0   0   0|   0     0 | 106B  400B|   0     0 |  27    24

0   0  99   0   0   0|   0     0 |  60B  346B|   0     0 |  26    23

0   0 100   0   0   0|   0     0 |  60B  346B|   0     0 |  22    20

0   0 100   0   0   0|   0     0 |  60B  346B|   0     0 |  19    21

0   0 100   0   0   0|   0     0 |  60B  346B|   0     0 |  20    17

0   0 100   0   0   0|   0   136k|  60B  346B|   0     0 |  20    25

0   0 100   0   0   0|   0     0 |  60B  346B|   0     0 |  25    29

进程管理命令

kill命令 向进程发送控制信号,以实现对进程管理

显示当前系统可用信号 kill -l

常用信号

1.SIGHUP 不关闭进程而重读配置文件

2.SIGINT 终止正在运行的进程 相当于ctrl+c

9.SIGKILL 杀死正在运行的进程

15.SIGTERM 终止正在运行的进程

18.SIGCONT 终止停止态

19.SIGSTOP 处于停止态

指定信号的方法

1.信号的数字标识 1,2,9

2.信号的完整名称 SIGHUP

3.信号的简写名称 HUP

向进程发信号

kill [-SIGNAL] PID

终止“名称”之下的所有进程

killall [-SIGNAL] program

Linux的作业控制 jobs

前台作业:通过终端启动,且启动后一直占据终端

后台作业:可以通过终端启动,但启动后即转入后台运行(释放终端)

让作业在后台运行

1.运行中的作业 ctrl+z

2.尚未启动的作业 command &

注意:此类作业虽然被送往后台运行,但是其依然与终端相关,终端断开,进程结束。如果希望送往后台后,剥离与终端的关系 nohup command &

查看所有作业:jobs

作业控制

fg [%#] 把指定后台作业调回前台

bg [%#] 让送往后台的作业在后台继续运行

kill [#] 终止作业

进程优先级:

静态优先级 100-139

进程默认启动时的nice值为0,优先级为120

renice -n 2 pid 把优先级增加到2

查看nice值 ps axo pid,comm,ni

sar tstar iostat iftop

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值