进程管理常用命令

pstree - display a tree of processes 树状结构显示进程

[root@203 ~]# pstree                                           #CentOS 6

init─┬─abrtd

     ├─acpid

     ├─atd

     ├─auditd───{auditd}

     ├─automount───4*[{automount}]

     ├─certmonger

     ├─crond

     ├─cupsd

     ├─dbus-daemon───{dbus-daemon}

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

                        └─hald-addon-inpu

           └─{hald}

     ├─irqbalance

     ├─mcelog

     ├─6*[mingetty]

     ├─rpc.statd

     ├─rpcbind

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

     ├─sshd───sshd───bash───pstree

     └─udevd───2*[udevd]

[root@lxk ~]# pstree                                             #CentOS 7

systemd─┬─AliYunDun───13*[{AliYunDun}]

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

        ├─agetty

        ├─aliyun-service

        ├─atd

        ├─auditd───{auditd}

        ├─crond

        ├─dbus-daemon

        ├─httpd───5*[httpd]

        ├─ntpd

        ├─polkitd───5*[{polkitd}]

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

        ├─sshd───sshd───bash───pstree

        ├─systemd-journal

        ├─systemd-logind

        ├─systemd-udevd

        ├─tuned───4*[{tuned}]

        └─wrapper─┬─java───13*[{java}]

                  └─{wrapper}

ps - report a snapshot of the current processes             显示当前进程的快照

[root@lxk ~]# ps au

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

root       495  0.0  0.0 110036   848 tty1     Ss+  Jul11   0:00 /sbin/agetty --noclear tty1 linux

root     16707  0.0  0.1 115524  2132 pts/0    Ss   23:05   0:00 -bash

root     16853  0.0  0.0 139504  1644 pts/0    R+   23:14   0:00 ps au

USER

发起进程的用户

PID

进程的ID

%CPU

进程所占CPU比率

%MEM

进程所占内存比

VSZ

虚拟内存集

RSS

常驻内存集

TTY

终端类型,?表示不知道终端类型

COMMAND

进程的路径,带中括号的表示内核进程

TIME

累积占据CPU时间

STAT

进程状态

进程状态:

D    uninterruptible sleep (usually IO)                                                                                     不可中断的睡眠状态

R    running or runnable (on run queue)                                                                                  运行

S    interruptible sleep (waiting for an event to complete)                                                         可中断的睡眠状态

T    stopped by job control signal                                                                                             被作业控制信号中断

t    stopped by debugger during the tracing                                                                        

X    dead (should never be seen)                                                                                     死进程(不应该被看到)

Z    defunct ("zombie") process, terminated but not reaped by its parent                  僵尸进程

For BSD formats and when the stat keyword is used, additional characters may be displayed:

<    high-priority (not nice to other users)                                                                              高优先级进程

N    low-priority (nice to other users)                                                                                      低优先级进程

L    has pages locked into memory (for real-time and custom IO)

s    is a session leader                                                                                                                 会话主导者

l    is multi-threaded (using CLONE_THREAD, like NPTL pthreads do)                           多线程进程

+    is in the foreground process group                                                                                   前台进程

选项有三种风格:

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:以用户为中心组织进程状态信息显示;

         o  field1, field2,...:自定义要显示的字段列表,以逗号分隔;

                   常用的fieldpid, ni, pri, psr, pcpu, stat, comm, tty, ppid, rtprio

                            ninice值;范围-2019 。进程可把自己的CPU时间让给别的进程。nice值越小,优先级越高

                            prioritypriority, 优先级;

                            rtprioreal time priority,实时优先级;

         -e:显示所有进程

         -f:显示完整格式的进程信息

         -F:显示完整格式的进程信息;

         -H:以层级结构显示进程的相关信息;

常用组合一、

[root@promote ~]# ps aux                      #BSD风格选项

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

root          1  0.0  0.3  44512  7196 ?        Ss   06:24   0:02 /usr/lib/systemd/systemd --switched-root --system --deseri

root          2  0.0  0.0      0     0 ?        S    06:24   0:00 [kthreadd]

root          3  0.0  0.0      0     0 ?        S    06:24   0:00 [ksoftirqd/0]

root          5  0.0  0.0      0     0 ?        S<   06:24   0:00 [kworker/0:0H]

         ......

         以下省略

        

         常用组合二、

         [root@promote ~]# ps -ef                        #UNIS风格选项

UID         PID   PPID  C STIME TTY          TIME CMD

root          1      0  0 06:24 ?        00:00:02 /usr/lib/systemd/systemd --switched-root --system --deserialize 21

root          2      0  0 06:24 ?        00:00:00 [kthreadd]

root          3      2  0 06:24 ?        00:00:00 [ksoftirqd/0]

root          5      2  0 06:24 ?        00:00:00 [kworker/0:0H]

root          6      2  0 06:24 ?        00:00:00 [kworker/u256:0]

         ......

         以下省略

                   UID:进程的执行者

PPID:父进程ID

CCPU的占用百分比 (不确定)

STIME:启动时间

TTY:与哪个终端相关

TIME:累积运行时间

CMD:启动此进程的命令

         常用组合三、

[root@promote ~]# ps -eFH

UID         PID   PPID  C    SZ   RSS PSR STIME TTY          TIME CMD

root          2      0  0     0     0   2 06:24 ?        00:00:00 [kthreadd]

root          3      2  0     0     0   0 06:24 ?        00:00:00   [ksoftirqd/0]

root          5      2  0     0     0   0 06:24 ?        00:00:00   [kworker/0:0H]

root          6      2  0     0     0   3 06:24 ?        00:00:00   [kworker/u256:0]

root          7      2  0     0     0   0 06:24 ?        00:00:00   [migration/0]

root          8      2  0     0     0   0 06:24 ?        00:00:00   [rcu_bh]

SZ

RSS:驻留集大小。任务所使用的非交换物理内存

PSR:运行于哪颗CPU之上

         常用组合四:-eo, axo

        

[root@promote ~]# ps axo pid,pcpu,psr,ni,stat,comm,tty,rtprio

   PID %CPU PSR  NI STAT COMMAND         TT       RTPRIO

     1  0.0   2   0 Ss   systemd         ?             -

     2  0.0   2   0 S    kthreadd        ?             -

     3  0.0   0   0 S    ksoftirqd/0     ?             -

     5  0.0   0 -20 S<   kworker/0:0H    ?             -

         ......

         以下省略

 

pgrep, pkill - look up or signal processes based on name and other attributes

         pgrep是查找进程,pkill是杀死进程,两者语法相同。

pgrep [options] pattern

-u uideffective user      显示谁运行的进程,发起进程的用户可能以别的用户的身份运行进程。

-U uidreal user     显示谁启动的进程

-t  TERMINAL:与指定的终端相关的进程;

-l:显示进程名

-a:显示完整格式的进程名;(CentOS 6中无此选项)

-P pid:显示此进程的子进程;

         示例:

                   [root@promote ~]# pgrep -u postfix -a                                    #显示postfix用户运行的进程PID及完整进程名

2706 pickup -l -t unix -u

2707 qmgr -l -t unix -u

[root@promote ~]# pgrep -U postfix -l                                     #显示postfix用户启动的进程PID及进程名

2706 pickup

2707 qmgr

[root@promote ~]# pgrep -at tty1                                   #显示tty1终端运行的进程的完整进程名

972 /sbin/agetty --noclear tty1 linux

[root@promote ~]# pgrep -au 0                                        #显示UID0的用户启动的进程及完整进程名

1 /usr/lib/systemd/systemd --switched-root --system --deserialize 20

2 kthreadd

3 ksoftirqd/0

5 kworker/0:0H

7 migration/0

......

以下省略

[root@promote ~]# pgrep -P 2701 -a                               #显示PID2701的进程的子进程的完整进程名

2706 pickup -l -t unix -u

2707 qmgr -l -t unix -u

 

[root@promote ~]# vim pkillout                                       #打开一个vim进程

 

[1]+  已停止               vim pkillout

[root@promote ~]# ps aux | grep vim                                      #在进程列表中查看进程

root       3106  2.9  0.2 153708  5108 pts/1    T    01:06   0:00 vim pkillout

root       3108  0.0  0.0 112664   976 pts/1    S+   01:06   0:00 grep --color=auto vim

[root@promote ~]# pkill vim                                                        #结束进程

[root@promote ~]# ps aux | grep vim                                      #再次查看还是有进程

root       3106  0.7  0.2 153708  5108 pts/1    T    01:06   0:00 vim pkillout

root       3111  0.0  0.0 112664   976 pts/1    S+   01:07   0:00 grep --color=auto vim

[root@promote ~]# fg                                                           #使用fg命令把vim切到前台,提示进程已结束

vim pkillout                                                                                

Vim: Caught deadly signal TERM

Vim: Finished.

已终止

pidof -- find the process ID of a running program                  根据进程名取出进程ID

[root@promote ~]# ps aux | grep man

root       3140  0.2  0.1 119468  2224 pts/1    S+   01:14   0:00 man pidof

root       3155  0.0  0.0 112664   976 pts/0    R+   01:15   0:00 grep --color=auto man

[root@promote ~]# pidof man

3140

top - display Linux processes

top - 02:05:59 up  2:16,  2 users,  load average: 0.00, 0.01, 0.05

Tasks: 390 total,   2 running, 385 sleeping,   3 stopped,   0 zombie

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

KiB Mem :  1868688 total,  1530752 free,   146112 used,   191824 buff/cache

KiB Swap:  2097148 total,  2097148 free,        0 used.  1547820 avail Mem

top: This portion consists of a single line containing:

program or window name, depending on display mode 进程或窗口名称,取决于运行模式

current time and length of time since last boot                         当前时间和从上一次启动到当前的时间

total number of users                                                                       用户总数

system load avg over the last 1, 5 and 15 minutes                            过去1515分钟系统的负载

TASK and CPU States

Line  1   shows  total tasks or threads, depending on the state of the Threads-mode toggle.  That total is further

classified as: running; sleeping; stopped; zombie

显示总进程数,取决于Threads-mode toggle。包括运行中、睡眠中、停止、僵尸

Line 2      shows CPU state percentages based on the interval since the last refresh.

us, user    : time running un-niced user processes               用户空间

sy, system  : time running kernel processes                             内核空间

ni, nice    : time running niced user processes                       调整nice时间

id, idle    : time spent in the kernel idle handler                    空闲

wa, IO-wait : time waiting for I/O completion                            等待IO时间

hi : time spent servicing hardware interrupts                                     硬中断

si : time spent servicing software interrupts                              软中断(模式切换)

st : time stolen from this vm by the hypervisor                          虚拟机偷走的时间

 

可按t改变显示方式

a           b    c         d

           %Cpu(s):  75.0/25.0  100[ ...

Where: a) is the combined us and ni percentage; b) is the sy percentage; c) is the total; and d) is  one  of  two

visual  graphs  of those representations. 

ausni一起的百分比;bsy(内核空间)百分比; C:合计        D:两个可视视图之一

MEMORY Usage

As a default, Line 1 reflects physical memory                            第一行:物理内存

Line 2 reflects mostly virtual memory                                 第二行:虚拟内存

                  

                   可按m改变显示方式,just like below:

                                      a    b      c

GiB Mem : 18.7/15.738   [ ...

GiB Swap:  0.0/7.999    [ ...

Where:  a)  is the percentage used; b) is the total available; and c) is one of two visual graphs of those representations.

a:使用的百分比;       b:总可用大小       c:两种可视化视力之一

各列排序方式:

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

M:以占据内存百分比排序;

T:累积占用CPU时间排序;

退出命令:q

修改刷新时间间隔:s        

         Change delay from 3.0 to         (出现在首部信息下面,输入时间,默认3秒)

终止指定的进程:k

         PID to signal/kill [default pid = 3073]      (出现在首部信息下面,输入PID即可)

选项:

-d #:指定刷新时间间隔,默认为3秒;

-b:以批次方式显示;

-n #:显示多少批次;

~]# top -b -n1            显示一次即退出

top - 02:05:59 up  2:16,  2 users,  load average: 0.00, 0.01, 0.05

Tasks: 390 total,   2 running, 385 sleeping,   3 stopped,   0 zombie

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

KiB Mem :  1868688 total,  1530752 free,   146112 used,   191824 buff/cache

KiB Swap:  2097148 total,  2097148 free,        0 used.  1547820 avail Mem

02:05:59   up

启动时间

2:16

运行时长

2 users

总用户数

load average

过去1515分钟系统的负载

390   total

总任务数

2   running

运行中的任务

385   sleeping

睡眠中任务

3   stopped

停止状态任务

0   zombie

僵尸态任务

us

用户空间所占比例

sy

系统空间所占比例

id

空闲

wa

等待IO时间

hi

硬中断

si

软中断

st

虚拟机偷走的时间

KiB Mem

物理内存

KiB   Swap

虚拟内存

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

PID

进程ID

USER

创建用户还是运行用户?

PR

用户优先级

NI

nice

VIRT

虚拟内存集

RES

常驻内存集

SHR

共享内存集

S

状态

%CPU

CPU占用比例

%MEM

内存占用比例

TIME+

累积CPU占用时间

COMMAND

进程完整名称

uptime - Tell how long the system has been running.  系统运行时长

[root@promote ~]# uptime

 02:21:50 up  2:32,  2 users,  load average: 0.00, 0.01, 0.05

三个字段分别为:系统启动时间、总运行时长、过去1分钟,5分钟,15分钟的平均负载


参考马哥教育课堂笔记

htop - interactive process viewer     交互式进程查看

支持鼠标操作

选项:

-d #:指定延迟时间间隔;

-u UserName:仅显示指定用户的进程;

-s COLUME:以指定字段进行排序;

子命令:

l:显示选定的进程打开的文件列表;

s:跟踪选定的进程的系统调用;

t:以层级关系显示各进程状态;

a:将选定的进程绑定至某指定的CPU核心;

                   按字母a后,可用从左边选定CPU,空为不选,不空为选择,用空格键选择。

uShow only processes owned by a specified user.显示指定用户的进程

                  按字母u之后,可从左侧选定要显示的用户进程

MSort by memory usage 以内存占用比例排序

PSort by processor usage CPU占用比例排序

TSort by time 以占用CPU使用时间排序

10.0% sys : 0.0% low:  0.0%                                                                          load average:0.06   0.05 0.05

20.0% sys : 0.0% low:  0.0%                                                                          Tasks:45; 1       running

30.0% sys : 0.0% low:  0.0%                                                                          Uptime:   02:53:49

40.0% sys : 0.0% low:  0.0%        

Mem:1.78G     used:194M       buffers:1.34M          cache:136M

Swp:2.00G        used:0K

PID   USER         PRI   NI     VIRT                   RES            SHR  S       CPU%       MEM%     TIME+      Command

CPU信息根据核心数分开显示。红色部分代表CPU各项信息

load average:过去1515分钟的平均负载

Uptime:启动时间

Mem:物理内存信息

Swp:虚拟内存信息

PID

程序ID

USER

用户

PRI

优先级

NI

nice

VIRT

虚拟内存集

RES

常驻内存集

SHR

共享内存集

S

状态

CPU%

CPU占用比例

MEM%

内存占用比例

TIME+

进程占用CPU时间

Command

进程名

PRIORITY (PRI)         The kernel's internal priority for the process, usually just its nice value plus twenty. Different for real-time processes.       

M_SIZE (VIRT)          The size of the virtual memory of the process.

M_RESIDENT (RES)   The resident set size (text + data + stack) of the process (i.e. the size of the process's used physical memory)

M_SHARE (SHR)        The size of the process's shared pages.

STATE (S)                      The state of the process:

S for sleeping (idle)  

R for running

D for disk sleep (uninterruptible)

Z for zombie (waiting for parent to read its exit status)

T for traced or suspended (e.g by SIGTSTP)

W for paging

PPID                           The parent process ID

vmstat - Report virtual memory statistics   虚拟内存统计

         vmstat  [options]  [delay [count]]

                            选项:

                                     -s:显示内存统计数据;

[root@promote ~]# vmstat

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

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

 1  0      0   1529644  1368 191400     0    0     3     0   436   46     0   1  99  0   0

[root@localhost ~]# vmstat 1 10                                #1秒刷新一次,总共刷新十次

[root@localhost ~]# vmstat 1                                      #1秒刷新一次

[root@localhost ~]# vmstat -s                                     #详细统计内存信息

procs

r:正在运行或等待运行的进程的个数;CPU上等待运行的任务的队列长度;

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

memory

swpd:交换内存使用总量;

free:空闲的物理内存总量;

buffer:用于buffer的内存总量;

cache:用于cache的内存总量;

swap

si  Amount of memory swapped in from disk (/s)

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

soAmount of memory swapped to disk (/s).

数据离开swap的速率(kb/s)

io

bi Blocks received from a block device (blocks/s).

从块设备读入数据到系统的速度

boBlocks sent to a block device (blocks/s).

保存数据至块设备的速率

system

inThe number of interrupts per second, including the clock. 中断速率;

csThe number of context switches per second.  上下文切换的速率(进程间切换速率);

cpu

us user space 用户空间占用的CPU比例

sysystem      系统空间占用的CPU比例

ididle    空闲

wawait        等待

st: stolen 被虚拟化所抢占的比例         当管理程序正在为另一个虚拟处理器服务时,虚拟CPUCPU花费在非自愿等待中的时间百分比。

 

 

iostat - Report Central Processing Unit (CPU) statistics and input/output statistics for devices and partitions      

[root@localhost ~]# iostat

Linux 3.10.0-693.el7.x86_64 (localhost.localdomain)    03/14/2018     _x86_64_          (2 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle

           0.07    0.00    0.17    0.05    0.00   99.71

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn

scd0              0.01         0.12         0.00       5250          0

sdb               0.00         0.06         0.00       2620          0

sda               0.48         7.69        10.28     336318     449462

[root@localhost ~]# iostat 1 10                                   #1秒刷新一次,总共刷新十次

         wrtn/swritten to the device expressed in a number of blocks per second

        

pmap - report memory map of a process     查看程序内存映射

pmap [options] pid [...]

         OPTIONS

-x:显示详细格式的信息

         另一种查看方式:cat  /proc/PID/maps

         [root@promote ~]# pmap -x 1

1:   /usr/lib/systemd/systemd --switched-root --system --deserialize 20

Address           Kbytes     RSS   Dirty Mode  Mapping

00007f047c9b9000      16       8       0 r-x-- libuuid.so.1.3.0

00007f047c9bd000    2044       0       0 ----- libuuid.so.1.3.0

00007f047cbbc000       4       4       4 r---- libuuid.so.1.3.0

00007f047cbbd000       4       4       4 rw--- libuuid.so.1.3.0

00007f047cbbe000     224      36       0 r-x-- libblkid.so.1.1.0

00007f047cbf6000    2048       0       0 ----- libblkid.so.1.1.0

00007f047cdf6000      12      12      12 r---- libblkid.so.1.1.0

00007f047cdf9000       4       4       4 rw--- libblkid.so.1.1.0

00007f047cdfa000       4       0       0 rw---   [ anon ]

00007f047cdfb000      84      12       0 r-x-- libz.so.1.2.7

00007f047ce10000    2044       0       0 ----- libz.so.1.2.7

00007f047d00f000       4       4       4 r---- libz.so.1.2.7

00007f047d010000       4       4       4 rw--- libz.so.1.2.7

....

以下省略

 

glances - A cross-platform curses-based monitoring tool

 

在主界面下,输入h进入帮助界面。

Glances 1.7.7 with PsUtil 2.2.1

 

               CAREFULWARNINGCRITICAL

  CPU user %      50.0  70.0  90.0            Swap %           50.0  70.0  90.0

  CPU system %    50.0  70.0  90.0                      Temp °C          60.0  70.0  80.0

  CPU iowait %    40.0  60.0  80.0            HDD Temp °C      45.0  52.0  60.0

  CPU steal %     10.0  15.0  20.0            文件系统         50.0  70.0  90.0

  Load             2.8   4.0  20.0           CPU process %   200.0 280.0 360.0

  RAM %           50.0  70.0  90.0          MEM process %    50.0  70.0  90.0

 

  a  自动排序                                       l  Show/hide logs

  c  根据CPU使用率排序                           b  Bytes or bits for network I/O

  m  根据内存占用比排序                            w  删除警告日志

  p  根据进程名字排序                               x  删除警告和严重级别的日

  i  Sort processes by I/O rate                                  1  全局CPU或者每个CPU的状态

  d  显示/隐藏硬盘I/O状态                           h  Show/hide this help screen

  f  显示/隐藏文件系统状态                            t  View network I/O as combination

  n  显示/隐藏network状态                          u  View cumulative network I/O

  s  显示/隐藏sensors状态                            z  Show/hide processes list

  y  显示/隐藏hddtemp状态                         q  Quit (Esc and Ctrl-C also work)

 

常用选项:

-b:以Byte为单位显示网上数据速率;

-d:关闭磁盘I/O模块;

-m:关闭mount模块;

-n:关闭network模块;

-t #:刷新时间间隔;

-1:每个cpu的相关数据单独显示;

-o {HTML|CSV}:输出格式;

-f  /PATH/TO/SOMEDIR:设定输出文件的位置;

-B @IP|HOST            Bind server to the given IPv4/IPv6 address or hostname

-c @IP|HOST             Connect to a Glances server by IPv4/IPv6 address or hostname

-s                                  Run Glances in server mode

C/S模式下运行glances命令

服务模式:

glances  -s  -B  IPADDR

 

IPADDR:本机的某地址,用于监听;

 

客户端模式:

glances  -c  IPADDR

 

IPADDR:是远程服务器的地址;

[root@promote ~]# glances -o HTML -f ./

打开另一终端,安装好python-jinja2firefox,提示如下:

Error: GDK_BACKEND does not match available displays

应该是需要图形界面打开

换到centos 6.5图形界面,成功打开。

C/S模式没试验成功

dstat - versatile tool for generating system resource statistics   

              生成系统资源信息的通用工具

常用选项:

-c --cpu:显示cpu相关信息;

-C #,#,...,total

-d, --disk:显示磁盘的相关信息

-D sda,sdb,...,tobal

-g:显示page相关的速率数据;

-mMemory的相关统计数据

-nInterface的相关统计数据;

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

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

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

 

--tcp

--udp

--raw

--socket

 

--ipc

 

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

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

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

--top-lantency:延迟最大的进程;

 

kill - terminate a process              用于向进程发送信号,以实现对进程的管理

SYNOPSIS

kill -l [signal]

kill [-s signal|-SIGNAL] pid..

OPTIONS:

-l, --list [signal]                   Print a list of signal names, or convert signal given as argument to a name.

                                     打印信号名字,或把给写的信号转换为信号名称

-s, --signal signal      Specify the signal to send. The signal may be given as a signal name or number.

                                     指定要发送的信号,signal可以是信号完整名称、信号简写名称、信号数字标识

常用信号:

1 SIGHUP:无须关闭进程而让其重读配置文件;

2SIGINT:终止正在运行的进程,相当于Ctrl+c。打断

3SIGQUIT:相当于ctrl+\

9SIGKILL:杀死运行中的进程;有可能会损害数据,很少用。

15SIGTERM:终止运行中的进程;通常是后台进程。常用、默认值

18SIGCONT:继续运行

19SIGSTOP:停止,送到后台

                   [root@promote ~]# kill -l 1

HUP

[root@promote ~]# kill -l hup

1

[root@promote ~]# ps aux | grep httpd

root       2906  0.1  0.1 226144  3644 ?        Ss   20:27   0:00 httpd

apache     2907  0.0  0.1 228228  3140 ?        S    20:27   0:00 httpd

apache     2908  0.0  0.1 228228  3140 ?        S    20:27   0:00 httpd

apache     2909  0.0  0.1 228228  3140 ?        S    20:27   0:00 httpd

apache     2910  0.0  0.1 228228  3140 ?        S    20:27   0:00 httpd

apache     2911  0.0  0.1 228228  3140 ?        S    20:27   0:00 httpd

root       2913  0.0  0.0 112664   976 pts/0    S+   20:27   0:00 grep --color=auto httpd

[root@promote ~]# kill 15 2893

[root@promote ~]# ps aux | grep httpd

root       2902  0.0  0.0 112664   976 pts/0    S+   20:25   0:00 grep --color=auto httpd

或者也可以

[root@promote ~]# kill -s 15 2906

[root@promote ~]# !ps

ps aux | grep httpd

root       2916  0.0  0.0 112664   976 pts/0    S+   20:28   0:00 grep --color=auto httpd

killall - kill processes by name           通过进程名杀死进程

         killall  [-SIGNAL]  program

         如不指定SIGNAL,默认为15

        

打开两个终端,一个终端打开man进程,另外一个终端运行killall man,运行man进程的终端提示如下:

         Manual page killall(1) line 1 (press h for help or q to quit)已终止

pgrep, pkill - look up or signal processes based on name and other attributes

         pgrep是查找进程,pkill是杀死进程,两者语法相同。

pgrep [options] pattern

-u uideffective user      显示谁运行的进程,发起进程的用户可能以别的用户的身份运行进程。

-U uidreal user     显示谁启动的进程

-t  TERMINAL:与指定的终端相关的进程;

-l:显示进程名

-a:显示完整格式的进程名;(CentOS 6中无此选项)

-P pid:显示此进程的子进程;


猜你喜欢

转载自blog.51cto.com/11975865/2173921