note_13.2_进程管理命令1

2019-03-04  本文已影响0人  人間失格_430b

Linux系统上的进程查看及管理工具

pstree, ps, pidof, pgrep, top, htop, glances, pmap, vmstat, dstat, kill, pkill, job, bg, fg, nohup, nice, renice, killall, ...

-CentOS 5: SysV init
-CentOS 6:upstart
-CentOS 7:systemd

/sbin/init,

pstree命令:

pstree - display a tree of processes

ps命令:

ps - report a snapshot of the current processes.

ps [options]:

1 UNIX options, which may be grouped and must be preceded by a dash.
2 BSD options, which may be grouped and must not be used with a dash.
3 GNU long options, which are preceded by two dashes.

启动进程的方式:
  系统启动过程中自动启动:与终端无关的进程;
  用户通过终端启动:与终端相关的进程;

选项:
  a:所有与终端相关的进程
  x:所有与终端无关的进程
  u:以用户为中心组织进程状态信息显示

常用组合之一:aux
  VSZ:Virtual memory Size虚拟内存集;
  RSS:Resident Size,常驻内存集;
  STAT:
   R:running
   S:interruptable sleeping
   D:uninterruptable sleeping
   T:Stopped
   Z:zombie
   +:前台进程
   l:多线程进程
   N:低优先级进程
   <:高优先级进程
   s:session leader

  -e:显示所有进程
  -f:显示完整格式的进程信息
常用组合之二:-ef

  -F:显示完整格式的进程信息
    C: cpu utilization
    PSR:运行于哪颗CPU之上
  -H:以层级结构显示进程的相关信息
常用组合之三:-eFH
常用组合之四:-eo, axo
  o field1, field2,...:自定义要显示的字段列表,以逗号分隔
    常用的field:pid, ni, pri, psr, pcpu, stat, comm, tty, ppid, rtprio
    ni:nice值
    priority:priority, 优先级
    rtprio:real time priority,实时优先级


pgrep, pkill命令:

look up or signal processes based on name and other attributes

pgrep [options] pattern
  -u uid:effective user
  -U uid:real user
  -t TERMINAL:与指定的终端相关的进程
  -l:显示进程名
  -a:显示完整格式的进程名
  -P pid:显示此进程的子进程

pidof命令:

根据进程名,取其pid;

top命令:

display Linux processes

[root@localhost ~]# top 
Tasks: 145 total,   1 running, 137 sleeping,   7 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
           用户       系统      nice    空闲    等待io   硬中断    软中断   stolen
KiB Mem :  1005656 total,   502616 free,   140120 used,   362920 buff/cache
KiB Swap:  2097148 total,  2097148 free,        0 used.   677244 avail Mem 

排序:
  P:以占据CPU百分比排序;
  M:以占据内存百分比排序;
  T:累积占用CPU时间排序;

首部信息:
  uptime信息:l命令
  tasks及cpu信息:t命令
  内存信息:m命令

  退出命令:q
  修改刷新时间间隔:s
  终止指定的进程:k

  选项:
    -d #:指定刷新时间间隔,默认为3秒
    -b:以批次方式显示
    -n #:显示多少批次

uptime命令:

[root@localhost ~]# uptime
 07:50:51 up  5:54,  2 users,  load average: 0.00, 0.01, 0.05

显示系统时间、运行时长及平均负载
load average:
  过去1分钟、5分钟和15分钟等待运行的进程队列的长度


pstree命令没有安装,使用yum search 和provides查到psmisc工具包

[root@localhost ~]# yum search pstree
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.shu.edu.cn
 * extras: centos.ustc.edu.cn
 * updates: mirrors.nju.edu.cn
=========================================================== Matched: pstree ============================================================
psmisc.x86_64 : Utilities for managing processes on your system
texlive-pst-tree.noarch : Trees, using pstricks
[root@localhost ~]# yum provides pstree
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ap.stykers.moe
 * extras: ap.stykers.moe
 * updates: mirrors.nju.edu.cn
updates/7/x86_64/filelists_db                                                                                    | 1.9 MB  00:00:01     
psmisc-22.20-15.el7.x86_64 : Utilities for managing processes on your system
Repo        : base
Matched from:
Filename    : /usr/bin/pstree
上一篇 下一篇

猜你喜欢

热点阅读